For the last few days I've been fighting the Identity system in combination with Entity framework Core. Here's some information prior to revealing my problem:
- Entity framework Core doesn't support lazy loading, this means that I'm using eager loading by saying which items to include
- In order to say which items of an object I would like to retrieve I override a method in each repository ( the properties retrieved are constant for now )
The Identity system I'm using is configured as :
services.AddIdentity<ApplicationUser, ApplicationRole>(options => { options.Cookies.ApplicationCookie.AutomaticChallenge = false; }) .AddUserManager<UserManager>() .AddRoleManager<RoleManager>() .AddUserStore<UserStore>() .AddRoleStore<RoleStore>() .AddEntityFrameworkStores<ApplicationDbContext, int>() .AddDefaultTokenProviders();
Now on to the problem itself:
I would like to use the identity system in order to generate tokens, get users etc. but I cannot do eager loading on the UserManager object itself as it's methods return Task<ApplicationUser> and the Include() method itself requires IQueryable ( to do eager loading ). What is the general way to be both be able to use eager loading and UserManager?