【问题标题】:IdentityDbContext<TUser> in Microsoft.AspNet.Identity.EntityFramework hide base DbContext constructorsMicrosoft.AspNet.Identity.EntityFramework 中的 IdentityDbContext<TUser> 隐藏基本 DbContext 构造函数
【发布时间】:2013-10-28 23:51:24
【问题描述】:

我正在使用 Visual Studio 2013 RTM 和 asp.net mvc 5 实体框架 asp net identity provider 我正在做以下事情

    public class MyContext : IdentityDbContext<MyUser>
    {
        public MyContext (DbCompiledModel model):base(model)
        {


        }    

        public DbSet<Foo> Foos{ get; set; }
        public DbSet<Bar> Bars{ get; set; }   

    }

并在这一行出现编译时错误

public MyContext (DbCompiledModel model):base(model)

IdentityDbContext 类隐藏了 DbContext 的所有构造函数。 有什么解决办法吗?

【问题讨论】:

    标签: visual-studio-2013 entity-framework-6 asp.net-mvc-5 asp.net-identity


    【解决方案1】:

    IdentityDbContext 只有两个构造函数

    • IdentityDbContext()
    • IdentityDbContext(字符串连接字符串)

    在继承 IdentityDbContext 时,您需要遵循其可用的指导。因此,您不能使用 DbCompiledModel 来构造上下文。

    【讨论】:

    • 有没有其他方法可以在不继承 IdentityDbContext 的情况下使用 asp.net 身份
    • 这是微软的糟糕设计
    • MS 提供的应用程序框架考虑了具有中等复杂性的最有用的功能。对于不同模式中更高级的用例和功能需求,您始终可以使用其接口制作该框架的自定义版本。 ASPNET.Identity.EntityFramework 本身的实现正在使用这些接口。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多