我正在尝试构建一个lambda表达式,该表达式将与其他表达式组合成一个相当大的表达式树以进行过滤.这工作正常,直到我需要通过子集合属性进行过滤.
如何构建一个Lambda表达式,它将在集合的属性上使用Any()进行过滤,该集合属性是根对象的属性?
例:
CurrentDataSource.Offices.Where(o => o.base_Trades.Any(t => t.Name == "test"))
Run Code Online (Sandbox Code Playgroud)
这是我如何静态构建表达式,但我需要动态构建它.对困惑感到抱歉.
编辑:这是我如何处理不太复杂的表达式的片段:
IQueryable<Office> officeQuery = CurrentDataSource.Offices.AsQueryable<Office>();
ParameterExpression pe = Expression.Parameter(typeof(Office), "Office");
ParameterExpression tpe = Expression.Parameter(typeof(Trades), "Trades");
Expression SimpleWhere = null;
Expression ComplexWhere = null;
foreach (ServerSideFilterObject fo in ssfo)
{
SimpleWhere = null;
foreach (String value in fo.FilterValues)
{
if (!CollectionProperties.Contains(fo.PropertyName))
{
//Handle singleton lambda logic here.
Expression left = Expression.Property(pe, typeof(Office).GetProperty(fo.PropertyName));
Expression right = Expression.Constant(value);
if (SimpleWhere == null)
{
SimpleWhere = Expression.Equal(left, right);
}
else
{
Expression e1 …Run Code Online (Sandbox Code Playgroud)