例如:
var Ex1 = Expression.Eq("DocAttrId", new decimal(-2));
var Ex2 = Expression.Eq("RowPos", new decimal(1));
var Ex3 = Expression.Eq("DocAttrId", new decimal(105510));
var Ex4 = Expression.Eq("DocAttrId", new decimal(-1));
var ExGroup1 = (Ex1 || Ex2);
var ExGroup2 = (Ex3 && ExGroup1);
var ExGroup3 = (Ex4 || ExGroup2);
_criteria.Add(ExGroup3);
如果我在列表或数组中包含所有Ex1 ... Ex4表达式,我可以通过构建标准来创建算法吗?
答案 0 :(得分:0)
var expressions = new[] {
Expression.Eq("DocAttrId", new decimal(-2)),
Expression.Eq("RowPos", new decimal(1)),
Expression.Eq("DocAttrId", new decimal(105510)),
Expression.Eq("DocAttrId", new decimal(-1)),
}
var ExGroup1 = Expression.Or(expressions[0], expressions[1]);
var ExGroup2 = Expression.And(expressions[2], ExGroup1);
var ExGroup3 = Expression.Or(expressions[3], ExGroup2);
_criteria.Add(ExGroup3);