简体   繁体   English

使用“包含”时如何过滤不需要的表?

[英]How do i filter the tables i do not need when I use “include”?

My EF nightmare continue. 我的EF梦night继续。 I noticed when I use eager loading include all related table will retrieve to my application. 我注意到,当我使用预先加载include所有相关表格将检索到我的应用程序。 So for example 1 have 3 tables/POCO like below, from below POCO and linq i just want to retrieve 2 tables but however when i check the generate T-SQL all 3 tables will retrieve, How do I exclude the table 3? 因此,例如1具有3个表/ POCO,如下所示,从POCO和linq下面,我只想检索2个表,但是当我检查生成T-SQL时,所有3个表都将检索,如何排除表3?

Poco 波科

public class TableA{
   public virtual ICollection<TableB> B { get; set; }
}

public class TableB{
   public virtual ICollection<TableC> C { get; set; }
}

public class TableC{

}

LINQ LINQ

var rs =(from family in context.A.Include("B")
select family).SingleOrDefault();

If you want fine grain control on which entities get loaded, use : 如果要对要加载的实体进行精细控制,请使用:

db.Configuration.LazyLoadingEnabled = false;

Note that for each instance of your DbContext, you can either get the lazy loading, OR the eager loading. 请注意,对于DbContext的每个实例,您可以获取延迟加载,也可以获取快速加载。

You shouldn't try to use both on the same instance. 您不应尝试在同一实例上同时使用两者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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