我有一个如下的方法:
public ICollection<T> GetEntitiesWithPredicate(Expression<Func<T, bool>> predicate)
{
// ...
}
我在另一个类中调用了一个方法,如下:
service.GetEntitiesWithPredicate(x => x.FoobarCollection.Where(y => y.Text.Contains(SearchText)));
但我总是会收到这个错误:
Lambda expression cannot be converted to '<typename>' because '<typename>' is not a delegate type
我需要改变什么才能让这个工作?
编辑:
我使用的是Entity Framework 6,如果我使用Any()而不是Where(),我总是只得到一个结果...我想将表达式传递给我的EF实现:
public ICollection<T> GetEntriesWithPredicate(Expression<Func<T, bool>> predicate)
{
using (var ctx = new DataContext())
{
return query.Where(predicate).ToList();
}
}
Any()
иҖҢдёҚжҳҜWhere()
гҖӮдҪ зҡ„Func<T, bool>
йңҖиҰҒиҝ”еӣһbool
пјҢдҪҶжҳҜWhere
иҝ”еӣһзҡ„жҳҜIEnumerable<T>
гҖӮ - haim770GetEntitiesWithPredicate(Expression<Func<T, bool>> predicate)
而不是仅仅的GetEntitiesWithPredicate(Func<T, bool>predicate)
吗?为什么你需要这个Expression
? - Peter - Reinstate MonicaWhere()
调用包装到了Entity Framework中... - haim770