How to eagerly load a many to many relationship with the entity framework code first?

前端 未结 1 1597
独厮守ぢ
独厮守ぢ 2021-01-13 22:11

I\'ll give the most basic example that I can think of for the purpose of clarity.

Lets say that I have two entities of the following form:

public cla         


        
1条回答
  •  执笔经年
    2021-01-13 22:45

    You want an Include() query to indicate that you want to eagerly load the related Course entities:

    var allStudents = context.Students.Include( s => s.Courses);
    

    Also make sure you have a

    using System.Data.Entity;
    

    in your code file so you can use the strongly typed Include() extension method.

    0 讨论(0)
提交回复
热议问题