简体   繁体   English

如何使用包含在新 select 中

[英]how to use include inside new select

I have use similar to this code for include my table:我使用与此代码类似的方法来包含我的表:

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();

I want select STD List for any PhoneList item with linq.我想要任何带有 linq 的 PhoneList 项目的 select STD 列表。 but its not working for my job.但它不适合我的工作。 These terms reconnect to the database whenever I want to use the list (STD).每当我想使用列表 (STD) 时,这些术语都会重新连接到数据库。 That makes it slower.这让它变慢了。

ex:前任:

foreach(var item in lst)
{
STD obj = item.PhoneList[0].STD;
}

also, I use db.Call.Include("PhoneList.STD") and this not working for job.另外,我使用db.Call.Include("PhoneList.STD")但这不适合工作。

You can use Linq extension method like this:您可以像这样使用 Linq 扩展方法:

if PhoneList is a table如果 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.

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