gpt4 book ai didi

c# - FilterExpression 的多个条件

转载 作者:可可西里 更新时间:2023-11-01 09:17:07 28 4
gpt4 key购买 nike

我正在使用条件表达式,但我无法将多个条件添加到 FilterExpression。任何人都可以帮忙吗?我在这里发布了我的源代码。

带过滤器的条件表达式:

  // Filter1
FilterExpression filter1 = new FilterExpression();
filter1.FilterOperator = LogicalOperator.And;
filter1.Conditions.Add(new ConditionExpression("A_LogicalName", ConditionOperator.Equal, id1));
filter1.Conditions.Add(new ConditionExpression("B_LogicalName", ConditionOperator.Equal, id2));
query.Criteria.Filters.Add(filter1);

//过滤器2

FilterExpression filter2 = new FilterExpression();
filter2.FilterOperator = LogicalOperator.And;
filter2.Conditions.Add(new ConditionExpression("B_LogicalName", ConditionOperator.Equal, id3));
filter2.Conditions.Add(new ConditionExpression("C_LogicalName", ConditionOperator.Equal, id4));
q_ShoppingCartItemQuantityCheck.Criteria.Filters.Add(filter2);

最佳答案

不确定我是否正确理解您的问题。如果我做对了,你想构建一个像这样的层次表达式:

(A_logicalName AND B_LogicalName) OR (B_LogicalName AND C_LogicalName)

对吗?

下面的方法不能解决您的问题吗?

query.Criteria = new FilterExpression(); 
query.Criteria.FilterOperator = LogicalOperator.Or;

FilterExpression filter1 = query.Criteria.AddFilter(LogicalOperator.And);
filter1.Conditions.Add(new ConditionExpression("A_LogicalName", ConditionOperator.Equal, id1));
filter1.Conditions.Add(new ConditionExpression("B_LogicalName", ConditionOperator.Equal, id2));

FilterExpression filter2 = query.Criteria.AddFilter(LogicalOperator.And);
filter2.Conditions.Add(new ConditionExpression("B_LogicalName", ConditionOperator.Equal, id2));
filter2.Conditions.Add(new ConditionExpression("C_LogicalName", ConditionOperator.Equal, id3));

另请参阅 MSDN 上的示例.

关于c# - FilterExpression 的多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14318160/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com