我对 LINQ 很陌生?请帮助我如何将以下通用 Lambda 函数转换为 lambda 表达式:
objects.Where(objects=>values.Contains(objects.DistrictId) );
我正在尝试创建一个完整的 lambda 表达式,而无需任何或直接调用。就像是 :
var innerItem = Expression.Parameter(typeof(Objects), "objects");
var innerProperty = Expression.Property(innerItem, "ID");
var innerMethodExpression = Expression.Call(innerProperty,null);
var innerLambda = Expression.Lambda<Func<Objects, bool>>(innerMethodExpression, innerItem);
var outerItem = Expression.Parameter(typeof(int[]), "item");
var containsMethod = typeof(string).GetMethod("Contains", new[] { typeof(int) });
var containsMethodExpression = Expression.Call(innerMethodExpression, containsMethod, innerLambda);
var outerLambda = Expression.Lambda<Func<Objects, bool>>(containsMethodExpression, outerItem);
collection = collection.AsQueryable<Objects>().Where(outerLambda);
但我不明白出了什么问题