我正在尝试创建表达式树以动态更改谓词, 我有一个像下面这样的实体
CatalogNo(pk)
VendorId
ProductToVendor(集合/导航属性)
我已经创建了如下表达式树
Expression<Func<Product, bool>> finalExpression = null;
List<Expression> expressionList = new List<Expression>();
var parameter = Expression.Parameter(typeof(Product), "p");
//Create predicate using expression tree
foreach (var keycolumn in request.KeyColumns)
{
expressionList.Add(Expression.Equal(
Expression.Property(parameter, keycolumn.ColumnName),
Expression.Constant(keycolumn.ColumnValue, typeof(string))
));
}
expressionList.Add(Expression.Equal(
Expression.Property(parameter, "SiteId"),
Expression.Constant(request.SiteId, typeof(int))
));
我想这样说
var vf = Context.Set<Product>().Where(p => p._ProductToVendor.Any(v => v.VendorId == VendorId) && p.SiteId == SiteId && p.CatalogNumber == catalogNo).ToList();
我尝试过 Stack Overflow | Expression tree for child collection List.Any
但是我无法获得预期的结果, 谁能帮忙!