如何在使用ASP.NET標(biāo)識時(shí)更改表名?我使用的是VisualStudio 2013的發(fā)布版本(RTM,而不是RC)(從MSDN 2013-10-18下載),因此使用的是AspNet.IdEntity的最新版本(RTM)。當(dāng)我創(chuàng)建一個(gè)新的Web項(xiàng)目時(shí),我選擇“個(gè)人用戶帳戶”進(jìn)行身份驗(yàn)證。這將創(chuàng)建以下表:阿斯佩羅AspNetUserClaimsAspNetUserLoginsAspNetUserRolesAspNetUser當(dāng)我注冊一個(gè)新用戶(使用默認(rèn)模板)時(shí),將創(chuàng)建這些表(上面列出),并且AspNetUsers表插入了一條記錄,其中包含:ID用戶名密碼散列安全郵票鑒別器此外,通過向類“ApplicationUser”添加公共屬性,我成功地向AspNetUsers表添加了其他字段,如“FirstName”、“LastName”、“PhoneNumber”等。這是我的問題。是否有方法更改上述表的名稱(第一次創(chuàng)建這些表時(shí)),還是始終使用AspNet我上面列出的前綴?如果表名可以不同的名稱,請解釋如何命名。-更新我實(shí)現(xiàn)了@郝公的解決方案。它確實(shí)創(chuàng)建了一個(gè)新表(例如,我稱它為MyUsers),但它仍然創(chuàng)建了AspNetUsers表。其目標(biāo)是將“AspNetUser”表替換為“MyUser”表。請參閱下面的代碼和創(chuàng)建的表的數(shù)據(jù)庫映像。實(shí)際上我想替換每一個(gè)AspNet桌子上寫著我自己的名字.。例如,MyRoles、MyUserClaims、MyUserLogins、MyUserRoles和MyUser。我如何做到這一點(diǎn),最后只有一組表?public class ApplicationUser : IdentityUser{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public string PhonePrimary { get; set; }
public string PhoneSecondary { get; set; }}public class ApplicationDbContext : IdentityDbContext<ApplicationUser>{
public ApplicationDbContext(): base("DefaultConnection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>().ToTable("MyUsers");
}}
3 回答

瀟湘沐
TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超6個(gè)贊
以下是我的工作解決方案:
public?class?ApplicationDbContext?:?IdentityDbContext<ApplicationUser>{ ????public?ApplicationDbContext() ????????:?base("DefaultConnection",?throwIfV1Schema:?false) ????{ ????} ????protected?override?void?OnModelCreating(DbModelBuilder?modelBuilder) ????{ ????????base.OnModelCreating(modelBuilder);?//?This?needs?to?go?before?the?other?rules! ????????modelBuilder.Entity<ApplicationUser>().ToTable("User"); ????????modelBuilder.Entity<IdentityRole>().ToTable("Role"); ????????modelBuilder.Entity<IdentityUserRole>().ToTable("UserRole"); ????????modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaim"); ????????modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogin"); ????} ????public?static?ApplicationDbContext?Create() ????{ ????????return?new?ApplicationDbContext(); ????}}

阿波羅的戰(zhàn)車
TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
using System.Data.Entity.ModelConfiguration;public class ApplicationUserConfig : EntityTypeConfiguration<ApplicationUser>{ public UserConfig() { ToTable("Users"); Property(u => u.LocationName).IsRequired(); }}
protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Configurations.Add(new ApplicationUserConfig()); ... }
- 3 回答
- 0 關(guān)注
- 576 瀏覽
添加回答
舉報(bào)
0/150
提交
取消