简体   繁体   English

实体框架渴望加载与相关对象相关的对象

[英]Entity Framework eager loading objects related to related object

I want to load eager Pictures object from User object when i,m trying to query request. 我想在查询请求时从User对象中加载渴望的Pictures对象。

Model 模型

User [Table] 用户[表]

--Pictures [navigational property] -图片[导航属性]

--Friends [navigational property] -朋友[导航财产]

Request [Table] 要求[表格]

--User [navigational property] --User [导航属性]

i,m using following query. 我使用以下查询。

var req = Context.Requests.Include(e => e.User).Include(d => d.User.Pictures).Where(c => c.Destination.Contains(CityName));

if i see the SQL server trace the query which executes has made join to pictures table and got the related data. 如果我看到SQL Server跟踪,则执行的查询已加入图片表并获得了相关数据。

but in C# is not able to get eager load pictures objects. 但在C#中无法获得渴望加载的图片对象。

when i try to seek any property of pictures object then [lazy loading occurs] and i can see another query in sql server trace. 当我尝试查找图片对象的任何属性时,[发生延迟加载],并且我可以在sql server跟踪中看到另一个查询。

how can i access pictures property without lazy loading.? 如何在不延迟加载的情况下访问图片属性?

您可以通过关闭edmx文件中的“延迟加载”选项,并在查询中使用Include(“ yourtable”)方法来做到这一点。

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

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