How does LINQ expression syntax work with Include() for eager loading

后端 未结 5 1518
天命终不由人
天命终不由人 2020-11-30 05:55

I have a query below, but I want to perform an Include() to eager load properties. Actions has a navigation property, User (Action.User)

1) My basic query:

5条回答
  •  孤城傲影
    2020-11-30 06:25

    I figured it out, thanks for the suggestions anyway. The solution is to do this (2nd attempt in my question):

    var qry = (from a in Actions
    join u in Users on a.UserId equals u.UserId    
    select a).Include("User")
    

    The reason intellisense didn't show Include after the query was because I needed the following using:

    using System.Data.Entity;
    

    Everything worked fine doing this.

提交回复
热议问题