Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Eager Loading Child Entities without Custom repository #5524


User avatar
0
drblakl created

Hello!

Using Asp.NET MVC 5 project and wondering what the best practice is to eager load required children of a Repository.

Do we need to make a custom repository to GetAllIncluding(), or is there another way that will load specific required children all the time if available?

Thank you in advance!


3 Answer(s)
  • User Avatar
    0
    ryancyq created
    Support Team

    Are you referring to EF6 or EFCore?

    You can use GetAllIncluding() if you know the navigation properties to load in in advance.

    However if you are looking to build a query and load the relevant navigation properties conditionally, you can try Include () followed by ThenInclude() available from EF Core APIs

  • User Avatar
    0
    drblakl created

    Using EF6

    And yes, I've used the GetAllIncluding() which works great!

    I'm wondering if it's possible to ensure eager loading of specific children always. Within the repository, or database configuration instead of within the app service or other layers.

  • User Avatar
    0
    ryancyq created
    Support Team

    @drblakl in that case, using the store pattern might be a better design. For example, AbpUserStore, AbpRoleStore and etc..

    You can then customize the IQueryable similar to this <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Zero/Authorization/Users/AbpUserStore.cs#L73">https://github.com/aspnetboilerplate/as ... ore.cs#L73</a>