需要以下查询的泛型表达式。
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")));
我想为一对一生成动态表达式,然后生成许多关系查询。
我得到了解决方案。
Expressionproeprtyexpression = Expression.Property(PTeamRoles, "TeamId"); 表达式值表达式 = 表达式常量("A"); Expression innerexpression = Expression.Lambda(Expression.Equal(proeprtyexpression, valueexpress), PTeamRoles); Expression 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);