[英]Entity Framework IQueryable has no where clause
I have these helper methods: 我有以下辅助方法:
public static IQueryable<T> All<T>(this IUnitOfWork unitOfWork)
where T : class
{
return unitOfWork.Context.Set<T>();
}
public static T Find<T>(this IUnitOfWork unitOfWork, Func<T, bool> predicate)
where T : class
{
return unitOfWork.All<T>().FirstOrDefault(predicate);
}
When I call the second one like this: 当我这样叫第二个:
var payment = _unitOfWork.Find<ContactRow>
(p => p.PaymentAttemptRef == paymentAttemptRef
&& p.ContactType == type);
I expect the predicate to become part of the query!! 我希望谓词成为查询的一部分!! but the problem is the select thats generated is without a where clause and pulls back all rows in the table.
但是问题是生成的select thats没有where子句,并拉回了表中的所有行。
Any idea why this is happening? 知道为什么会这样吗? The second method calls the first, which returns an iqueryable so i thought that would do it no?
第二种方法调用第一种,它返回一个iqueryable,所以我认为这样做不会吗?
您需要更改扩展方法以采用Expression<Func<T, bool>>
以便可以将其转换为SQL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.