How to load related data in Repository pattern Entity framework 3.1

HirenMore
May 20, 2021

--

Install the Proxies package using nuget manager

Install-Package Microsoft.EntityFrameworkCore.Proxies

Enable LazyLoadingProxies You can enable it with a call to UseLazyLoadingProxies:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseLazyLoadingProxies()
.UseSqlServer(myConnectionString);

Or when using AddDbContext:

Go inside the Startup.cs file inside the ConfigureServices method

services.AddDbContext<BloggingContext>(
b => b.UseLazyLoadingProxies()
.UseSqlServer(myConnectionString));

if you have used the DbContextPool than

services.AddDbContextPool<AdhyatmavaniContext>(
b => b
.UseLazyLoadingProxies()
.UseSqlServer(myConnectionString));

--

--

HirenMore
HirenMore

Written by HirenMore

I am a Full-Stack Developer, Photographer, Traveler and DayDreamer.

No responses yet