7

I asked a question (got a -2 for my efforts but thats besides the point). The only answer indicated I should use lazyloading by adding it in StartUp.cs.

However, no matter what I do I cannot add this. I followed the direction of the link the author suggested as well as what the author did and in all cases I got the following.

Severity Code Description Project File Line Suppression State Error CS1061 'DbContextOptionsBuilder' does not contain a definition for 'UseLazyLoadingProxies' and no accessible extension method 'UseLazyLoadingProxies' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?) JobsLedger.API C:\Users\simon\OneDrive\Documents\1.0 - AURELIA\1.0 - JobsLedgerSPA -ASPNET CORE 3.1\JobsLedger.API\Startup.cs 74 Active

If there is an assembly reference I wonder if someone might point me in the right direction.

This is what I currently have along with the modification as per the link the author for that question suggested.

    services.AddDbContext<CATALOGContext>(options => options.UseSqlServer(_configuration.GetConnectionString("CatalogConnection"), b => b.MigrationsAssembly("JobsLedger.CATALOG")));
    services.AddDbContext<DATAContext>(options => options.UseLazyLoadingProxies().UseSqlServer(_configuration.GetConnectionString("TenantDbConnection"), a => a.MigrationsAssembly("JobsLedger.DATA")));

How do I configure these lines for ".UseLazyLoadingProxies" as its currently saying this is not available?

si2030
  • 3,895
  • 8
  • 38
  • 87

1 Answers1

8

Per the comments and my own research on this issue, add Microsoft.EntityFrameworkCore.Proxies to your package as it contains the UseLazyLoading method you need to add to your DB Context options.

Eric Conklin
  • 539
  • 4
  • 17
  • Side note - I don't actually recommend using lazy loading. I would prefer explicit loading statements within entity framework core such as .Include() or .Select() to ensure good performance. If you have a small database you can enable lazy loading no problem but larger databases should have explicit loads. – Eric Conklin Jan 27 '23 at 18:52