简体   繁体   中英

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.

Any idea why this is happening? The second method calls the first, which returns an iqueryable so i thought that would do it no?

您需要更改扩展方法以采用Expression<Func<T, bool>>以便可以将其转换为SQL。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM