Is it optimised to include in EF Core?



  • The question is whether the downloading of EF Core data is optimized?
    Specifically, there's a code for loading orders and counterparts on orders:

    await dbContext.Orders.Where(x => !x.IsDeleted).Include(x => x.Counterparty).ToListAsync();
    

    The question is, if I have five different orders, but with one counterpart, he'll unload five times the same counterparty or find a link in the cash and use it?
    Trying to find some information in the google-- couldn't, maybe he was looking for something wrong?
    I'll be happy with any answers.



  • Documentation https://docs.microsoft.com/en-us/ef/core/querying/related-data/eager#eager-loading There is a Caution warning of possible productivity problems.

    Documentation https://docs.microsoft.com/en-us/ef/core/querying/single-split-queries The cause of the problem is described. Load data can be duplicated, just as you fear.
    The way to eliminate it is to use separated requests: .AsSplitQuery()

    Useful references:

    https://docs.microsoft.com/en-us/ef/core/change-tracking/debug-views - so you can see how things happen to traceable things.

    https://docs.microsoft.com/en-us/ef/core/change-tracking/entity-entries - How to use traceable objects.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2