第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在使用ASP.NET標(biāo)識時(shí)更改表名?

如何在使用ASP.NET標(biāo)識時(shí)更改表名?

慕虎7371278 2019-07-22 10:40:21
如何在使用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();
????}}


查看完整回答
反對 回復(fù) 2019-07-22
?
阿波羅的戰(zhàn)車

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊

還可以創(chuàng)建配置類并指定每個(gè)標(biāo)識類的每個(gè)細(xì)節(jié),例如:

using System.Data.Entity.ModelConfiguration;public class ApplicationUserConfig : EntityTypeConfiguration<ApplicationUser>{
    public UserConfig()
    {
        ToTable("Users");
        Property(u => u.LocationName).IsRequired();
    }}

然后將這些配置包含在OnModelCreating()方法中:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Configurations.Add(new ApplicationUserConfig());
        ...
    }

這將使您完全控制標(biāo)識類的每個(gè)方面。


查看完整回答
反對 回復(fù) 2019-07-22
  • 3 回答
  • 0 關(guān)注
  • 576 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號