【问题标题】:Schema first and simple membership?架构优先和简单的成员资格?
【发布时间】:2013-02-05 12:47:20
【问题描述】:

我正在尝试首先使用模式 (EF5) 构建数据库,并添加简单的成员资格。

在“绘制”我的架构后,我添加了用户配置文件表(UserId&UserName),删除了

过滤器:InitializeSimpleMembershipAttribute,去掉这一切..

//public class UsersContext : DbContext
//{
//    public UsersContext()
//        : base("DefaultConnection")
//    {
//    }

//    public DbSet<UserProfile> UserProfiles { get; set; }

//}

//[Table("UserProfile")]
//public class UserProfile
//{
//    [Key]
//    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
//    public int UserId { get; set; }
//    public string UserName { get; set; }
//}

在生成的类中(首先按模式)我尝试手动添加

[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]

到我的 UserProfile 类

我也在我的 AppStart 中注册了:

WebSecurity.InitializeDatabaseConnection("Model1Container", "UserProfile",
    "UserId", "UserName", autoCreateTables: true);

但在调试时我收到此错误:

Unable to find the requested .Net Framework Data Provider.  It may not be installed

WebSecurity.InitializeDatabaseConnection("Model1Container", "UserProfile",

有什么好的做法吗?

是否可以先使用模式?

【问题讨论】:

    标签: entity-framework asp.net-mvc-4 asp.net-membership simplemembership


    【解决方案1】:

    注意,您已删除以下具有连接名称的部分。

    public UsersContext()
    //        : base("DefaultConnection")
    //    {
    //    }
    

    只需将其添加到您的上下文类中即可。是的,您可以使用代码优先方法来做到这一点,我认为这比您现在所做的要容易得多..

    【讨论】:

    • 谢谢。我想我会使用代码优先方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    相关资源
    最近更新 更多