Load child entity on the fetch of the Parent entity EFCore

前端 未结 3 1144
感情败类
感情败类 2021-01-22 16:50

I have the below model. What is the better way to load the parent entity with child entity at the time of fetching from the DB with find method?

Parent Entity:

3条回答
  •  遇见更好的自我
    2021-01-22 17:03

    In EF, there is a concept called Eager Loading using .Include.

    MS Docs - Loading Related Data - EF Core

    .NET Fiddle

    using MyContext context = new MyContext();
    
    IList clients =
        context.Clients
            .Include(c => c.Address)
            .Where(c => c.LastName == "patel")
            .ToList();
    

提交回复
热议问题