简体   繁体   中英

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

My EF nightmare continue. I noticed when I use eager loading include all related table will retrieve to my application. 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?

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

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.

You shouldn't try to use both on the same instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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