Search code examples
asp.net-mvcentity-frameworkasp.net-mvc-4asp.net-mvc-5datacontext

How to include more than one class while fetching from database


I want to include two classes while fetching. I know how to do this with one class but I am not sure how to do it with two.

Here I am including Student

var service = dc.service.Include("Student").OrderBy(i => i.id);

I am not sure how to add both Student and Program


Solution

  • You can just chain multiple Include methods.

    var service = dc.service.Include("Student").Include("Program").OrderBy(i => i.id);