我目前正在嘗試使用EF6 Code構建一個新的應用程序,我設法基於我的模型創建數據庫沒有問題。實體框架(代碼優先) - &ASP.net會員提供
現在我想要做的是使用asp.net成員資格功能。所以我將不得不在我的數據庫中有數據庫模式。
我該怎麼做?
有關使用simplemembershipprovider與EF的互聯網上的信息,但它很混亂。
只要你有什麼我迄今所做的想法...(下同)
那麼,什麼是使用會員與EF最好的方法是什麼?
namespace AsoRock.Data.DTOs
{
public class Customer
{
[Key]
public int CustomerId { get; set; }
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string HomeNumber { get; set; }
public string MobileNumber { get; set; }
public string Gender { get; set; }
public DateTime Dob { get; set; }
}
public class Order
{
[Key]
public int OrderId { get; set; }
public Address Address { get; set; }
public Customer Customer { get; set; }
public List<Product> Products { get; set; }
}
public class Product
{
[Key]
public int ProductId { get; set; }
public string ProductName { get; set; }
public decimal ProductPrice { get; set; }
}
public class Address
{
[Key]
public int AddressId { get; set; }
public Customer Customer { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string City { get; set; }
public string PostCode { get; set; }
public string LastUsed { get; set; }
public bool isDefault { get; set; }
}
public class AsoRockContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
public DbSet<Address> Addresses { get; set; }
public DbSet<Order> Orders { get; set; }
// public DbSet<Product> Products { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Order>().HasMany(p => p.Products).WithMany().Map(m =>
{
m.MapLeftKey("OrderId").MapRightKey("ProductId").ToTable("OrderdProducts");
});
base.OnModelCreating(modelBuilder);
}
}
}
哪個版本的asp.net mvc? – Miller