IdentityDbContext <ApplicationUser> vs DbContext for Repository

teh*_*ner 5 asp.net-mvc entity-framework repository asp.net-identity

我正在尝试构建我的IRepository接口和具体类EntityFrameworkGenericRepository,但我对DbContext有一个问题.

在EFGenericRepository中的以前版本的MVC中,您将引用EntityFramework并使用DbContext,这就是它.

现在我正在使用具有ASP.NET标识的MVC5,我需要为IdentityDbContext切换DbContext,但这意味着我需要引用ASP.NET标识.

有没有办法解决这个问题,还是完全没问题?

构造函数和属性的片段

public class EntityFrameworkGenericRepository<T> : IGenericRepository<T> where T: class
{
    protected IdentityDbContext<ApplicationUser>Context = null;

    protected DbSet<T> DbSet
    {
        get
        {
            return Context.Set<T>();
        }
    }


    public EntityFrameworkGenericRepository(IdentityDbContext<ApplicationUser> context)
    {
        if (context == null)
        {
            throw new ArgumentNullException("context");
        }
        Context = context;
    }
Run Code Online (Sandbox Code Playgroud)

这是我的WebAppDbContext:

public class WebAppDbContext : IdentityDbContext<ApplicationUser>
{
    public WebAppDbContext()
        : base(nameOrConnectionString: "DefaultConnection") { }

    public DbSet<User> User { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

        base.OnModelCreating(modelBuilder);
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 -1

这对我来说看起来不错。您有什么具体的担忧吗?