Using Entity Framework navigation properties without creating lots of queries (avoiding N+1)
- 阅读更多 关于 Using Entity Framework navigation properties without creating lots of queries (avoiding N+1)
I've been using Entity Framework Profiler to test my data access in an MVC project and have come accross several pages where I'm making far more db queries than I need to because of N+1 problems. Here is a simple example to show my problem: var club = this.ActiveClub; // ActiveClub uses code similar to context.Clubs.First() var members = club.Members.ToList(); return View("MembersWithAddress", members); The view loops through Members and then follows a navigion property on each member to also show their address. Each of the address requests results in an extra db query. One way to solve this