-1

以下查询需要通用表达式。

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")));

我想为一对一然后很多关系查询生成动态表达式。

4

1 回答 1

0

我得到了解决方案

表达式 proeprtyexpression = Expression.Property(PTeamRoles, "TeamId"); 表达式值express = Expression.Constant("A"); //表达式内部表达式 = Expression.Lambda(Expression.Equal(proeprtyexpression, valueexpress), PTeamRoles); 表达式内部表达式 = 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);
于 2013-02-01T07:14:32.163 回答