Wednesday 30 March 2016

What is eager loading in Entity Framework?

It is the process in which related objects are loaded automatically with parent objects. We can also say that a query of one type of entity load related entity as part of query.
For Example we have School Database in which Student, Address etc. Tabled or entities are there. While fetching of Student table data, at the same time we want to load Address table data also.
Sample:-
SchoolDBContext   db= new SchoolDBContext();
var res=db.Student.Include(“Address”).Take(10);
foreach(var  student  in  res)
{
     Console.WriteLine(student.Name);
     foreach(var  address  in  Student.Address)
     {
           Console.WriteLine(address.PamanentAddress);
     }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.