How to load navigation properties on an IdentityUser with UserManager

前端 未结 3 1716
离开以前
离开以前 2020-12-03 05:01

I\'ve extended IdentityUser to include a navigation property for the user\'s address, however when getting the user with UserManager.FindByEmailAsync

3条回答
  •  时光取名叫无心
    2020-12-03 05:21

    I found it useful to write an extension on the UserManager class.

    public static async Task FindByUserAsync(
        this UserManager input,
        ClaimsPrincipal user )
    {
        return await input.Users
            .Include(x => x.InverseNavigationTable)
            .SingleOrDefaultAsync(x => x.NormalizedUserName == user.Identity.Name.ToUpper());
    }
    

提交回复
热议问题