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:
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
?
The simplest way maybe to call UserManger.Users directly. Like this:
ApplicationUser user = await userManager.Users.Include(s => s.Sales).Where(e => e.Email == "[email protected]").FirstOrDefaultAsync();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With