c# – FilterExpression的多个条件

前端之家收集整理的这篇文章主要介绍了c# – FilterExpression的多个条件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用条件表达式,但是我无法向FilterExpression添加多个条件.
可以帮忙吗我已经在这里发布了我的源代码.

带过滤器的ConditionExpression

// 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",id2));
query.Criteria.Filters.Add(filter1);

// Filter2

FilterExpression filter2 = new FilterExpression();
filter2.FilterOperator = LogicalOperator.And;
filter2.Conditions.Add(new ConditionExpression("B_LogicalName",id3));
filter2.Conditions.Add(new ConditionExpression("C_LogicalName",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",id2));

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

另见MSDN上的例子.

猜你在找的C#相关文章