简体   繁体   中英

How to add a where clause to this Entity Framework Linq statement

I have set up EF 4.3 using a generic respository/uow pattern.

A typical method looks like this:

using (var uow = new UnitOfWork(ConnectionString.PaydayLenders))
{
    var r = new CrudRepo<Tier>(uow.Context);
    return r.Find()
    .Include("CommissionTiers.MatchService.Provider")
    .ToList();
}

As you can see, I also include other tables in the fetch using navigation properties.

In this example, a Tier has many CommissionTiers, CommissionTiers has a MatchService and MatchService has a provider.

What I want to be able to do is select where CommissionTier.Status = 1 and Provider = 1. Is there a way this can be incorporated into this statement/method?

Try this:

Where(t => t.CommissionTiers
            .Any(ct => ct.Status == 1 && ct.MatchService.Provider == 1))

Because you have navigation properties in place there is no need for an explicit join in your LINQ statement.

您可以使用Join获取所需的功能。

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