![](/img/trans.png)
[英]Place if statement inside a where clause in Linq for Entity framework
[英]How to add a where clause to this Entity Framework Linq statement
我已經使用通用存儲庫/ uow模式設置了EF 4.3。
一種典型的方法如下所示:
using (var uow = new UnitOfWork(ConnectionString.PaydayLenders))
{
var r = new CrudRepo<Tier>(uow.Context);
return r.Find()
.Include("CommissionTiers.MatchService.Provider")
.ToList();
}
如您所見,我還使用導航屬性在獲取中包括其他表。
在此示例中,一個層具有許多CommissionTiers,CommissionTiers具有MatchService,而MatchService具有提供者。
我要執行的操作是選擇CommissionTier.Status = 1且Provider = 1的位置。有沒有辦法將其合並到此語句/方法中?
嘗試這個:
Where(t => t.CommissionTiers
.Any(ct => ct.Status == 1 && ct.MatchService.Provider == 1))
因為您具有導航屬性,所以無需在LINQ語句中進行顯式聯接。
您可以使用Join獲取所需的功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.