需要以下查询的通用表达式。
I don't want to use the Dynamic library and Predicate builder.
我正在动态生成表达式。
var test = entity.User.Where(PUser => PUser.Role.TeamRoles.Any(PTeamRoles => PTeamRoles.TeamId == "222")));
我想生成一对一的动态表达式,然后是很多关系查询。
答案 0 :(得分:0)
我得到了解决方案
Expression proeprtyexpression = Expression.Property(PTeamRoles,“TeamId”); 表达式valueexpress = Expression.Constant(“A”); //表达式innerexpression = Expression.Lambda(Expression.Equal(proeprtyexpression,valueexpress),PTeamRoles); 表达式innerexpression = Expression.Lambda(ExcelExpressionHelper.ApplyOperator(proeprtyexpression,valueexpress,“StartsWith”),PTeamRoles);
Type winnertype = PTeamRoles.Type;
Type woutertype = PRole.Type;
var wouterProperty = Expression.Property(PRole, "TeamRoles");
var outerMethodExpression = Expression.Call(typeof(Enumerable), "Any", new[] { winnertype }, wouterProperty, innerexpression);