Entity framework 当我们可以使用应用程序dbcontext时,为什么要使用UserManager访问用户配置文件信息?

Entity framework 当我们可以使用应用程序dbcontext时,为什么要使用UserManager访问用户配置文件信息?,entity-framework,asp.net-mvc-5,asp.net-identity,asp.net-core-mvc,Entity Framework,Asp.net Mvc 5,Asp.net Identity,Asp.net Core Mvc,当我在谷歌上搜索如何查找UserProfile属性时,我会得到结果,所有这些结果都使用UserManager访问UserProfile自定义属性 因此,如果我有一个自定义的应用程序用户 public class ApplicationUser : IdentityUser { public int AccType { get; set; } // } 在我的控制器中,简化的代码如下 ApplicationUser usr = _context.Users.Si

当我在谷歌上搜索如何查找
UserProfile
属性时,我会得到结果,所有这些结果都使用
UserManager
访问
UserProfile
自定义属性

因此,如果我有一个自定义的
应用程序用户

public class ApplicationUser : IdentityUser
    {
        public int AccType { get; set; } // 
    }
在我的控制器中,简化的代码如下

ApplicationUser usr = _context.Users.SingleOrDefault(u => u.UserName == User.Identity.Name);

此方法向代码公开
UserProfile
属性。那么为什么每个人都在使用
UserManager

UserManager
包括验证规则和特定于用户通常执行的任务的帮助方法,如使用安全密码创建新用户、验证输入的密码、添加/删除角色等

是的,您可以直接使用
ApplicationDbContext
,但您需要针对已定义的
DbSet编写查询,此外,它还可以在执行搜索之前规范化名称

查看并查看
UserManager
通过
DbSet
提供了什么