EF Code First和ASP.NET成员资格提供程序

时间:2012-08-04 08:48:16

标签: asp.net-mvc-3 entity-framework ef-code-first asp.net-roles

我正在使用MVC 3构建Web应用程序。它具有不同角色和特权的用户。我正在使用EF Code First方法进行数据库创建。我的用户模型类是:

public class Users
    {
        public int UserID { get; set; }

        public Name Name { get; set; }

        public Address Address { get; set; }

        public Contact Contact { get; set; }

    }

    public class Name
    {
        [Required, MaxLength(50), Display(Name = "First Name"), Column("FirstName")]
        public string FirstName { get; set; }

        [MaxLength(50), Display(Name = "Middle Name"), Column("MiddleName")]
        public string MiddleName { get; set; }

        [Required, MaxLength(50), Display(Name = "Last Name"), Column("LastName")]
        public string LastName { get; set; }
    }

    public class Address
    {
        [Required, MaxLength(50), Display(Name = "Street"), Column("Street")]
        public string Street { get; set; }

        [Required, MaxLength(50), Display(Name = "City"), Column("City")]
        public string City { get; set; }

        [Required, MaxLength(50), Display(Name = "Country"), Column("Country")]
        public string Country { get; set; }

        [Required, MaxLength(5), Display(Name = "Postal Code"), Column("PostalCode")]
        public string PostalCode { get; set; }
    }

    public class Contact
    {
        [Required, MaxLength(50), Display(Name = "Email"), Column("Email")]
        public string Email { get; set; }

        [Required, MaxLength(50), Display(Name = "Phone"), Column("Phone")]
        public string Phone { get; set; }

        [Required, MaxLength(50), Display(Name = "Fax"), Column("Fax")]
        public string Fax { get; set; }
    }

但是对于角色和身份验证,我想使用aspnetdb.mdf文件夹的默认App_Data。如何将Users表格与Users的默认aspnetdb.mdf表格相关联?

1 个答案:

答案 0 :(得分:0)

由于您似乎正在创建一个新网站和数据库,我不会这样做,除非您出于任何原因必须这样做。

我会使用UserProfile为用户存储地址,电话,传真等其他信息,请查看Membership User Profile API以添加自定义属性。

同样this article可能会有所帮助,它有点旧,但如果需要,它可以帮到你。