简体   繁体   中英

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.

Model

User [Table]

--Pictures [navigational property]

--Friends [navigational property]

Request [Table]

--User [navigational property]

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.

but in C# is not able to get eager load pictures objects.

when i try to seek any property of pictures object then [lazy loading occurs] and i can see another query in sql server trace.

how can i access pictures property without lazy loading.?

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

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