[英]Linq - where condition on child table
我們可以在下面的查詢的子表中的列上應用where條件嗎?
患者是主表,我需要在以下條件下用“評估”表中的列來補充
Where(a => a.Date >= startdate && a.Date < stopdate && a.patient.assess.column1 == 10)
完整查詢
=> dc.Patient
.Include("first")
.Select(a => new
{
Patient = a,
Date = a.Assess.Max(x => x.Date),
M3 = a.M3,
Assess = a.Assess,
Details = a.Assess
.Select(x => new
{
x.Key,
x.Team
})
})
.Where(a => a.Date >= startdate && a.Date < stopdate)
.OrderBy(a => a.Date)
.Take(batchSize)
.ToList()
);
您可以在lambda中使用其他子/嵌入的lambda語句。 在這種情況下,可以在Where語句中引用IEnumerable.Any語句。 如果存在與lambda匹配的任何條件,並且可以將其稱為Assess
是一個集合,則Any會返回true
。
我的假設是:
Assess
是一個強類型集合 Assess
實例的property column
等於10
的值,則您希望任何Where
子句都匹配 碼:
=> dc.Patient
.Include("first")
.Select(a => new
{
Patient = a,
Date = a.Assess.Max(x => x.Date),
M3 = a.M3,
Assess = a.Assess,
Details = a.Assess.Select(x => new
{
x.Key,
x.Team
})
})
.Where(a => a.Date >= startdate && a.Date < stopdate && a.Assess.Any(ass => ass.column1 == 10))
.OrderBy(a => a.Date)
.Take(batchSize)
.ToList()
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.