[英]how to use include inside new select
我使用與此代碼類似的方法來包含我的表:
var lst = (from o in db.Call
where o.date >= mydate
select new {
o.Title,
o.Name,
PhoneList = o.PhoneList.Include("STD").where(o2 => o2.Id == 6).ToList()
}).ToList();
我想要任何帶有 linq 的 PhoneList 項目的 select STD 列表。 但它不適合我的工作。 每當我想使用列表 (STD) 時,這些術語都會重新連接到數據庫。 這讓它變慢了。
前任:
foreach(var item in lst)
{
STD obj = item.PhoneList[0].STD;
}
另外,我使用db.Call.Include("PhoneList.STD")但這不適合工作。
您可以像這樣使用 Linq 擴展方法:
如果 PhoneList 是一個表
var lst = db.Call.Where(a=>a.date >= mydate).Include(a=> a.PhoneList).Include(a=> a.PhoneList.Select(b=>b.STD)).Select(a=> new {
a.Title,
a.Name,
PhoneList = a.PhoneList.where(o2 => o2.STD.Id == 6)}).ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.