當我使用ASP.NET身份第一代碼方法時,我想以自己的方式在AspNetUsers表中生成列。我不需要存儲具有空值的多個列。我只需要列ID,SecurityStamp和用戶名。 只發布,我發現在這裏:AspNet Identity 2.0 Email and UserName duplication,但它仍然不受歡迎(由於桑託什評論中的錯誤)。ASP.NET身份從AspNetUsers表中刪除列
那麼有人可以告訴我如何解決這個問題嗎?
編輯:甚至有可能刪除這些列/屬性中的一些?
謝謝
當我使用ASP.NET身份第一代碼方法時,我想以自己的方式在AspNetUsers表中生成列。我不需要存儲具有空值的多個列。我只需要列ID,SecurityStamp和用戶名。 只發布,我發現在這裏:AspNet Identity 2.0 Email and UserName duplication,但它仍然不受歡迎(由於桑託什評論中的錯誤)。ASP.NET身份從AspNetUsers表中刪除列
那麼有人可以告訴我如何解決這個問題嗎?
編輯:甚至有可能刪除這些列/屬性中的一些?
謝謝
簡短的回答是否,不是沒有滾動自己的實現。或者您可以等待他們在codeplex上打開源代碼asp.net標識。誰知道會花多長時間。
默認實現包括所有這些未使用的列(請參見下文)。
// Summary:
// Default EntityFramework IUser implementation
//
// Type parameters:
// TKey:
//
// TLogin:
//
// TRole:
//
// TClaim:
public class IdentityUser<TKey, TLogin, TRole, TClaim> : IUser<TKey>
where TLogin : Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin<TKey>
where TRole : Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole<TKey>
where TClaim : Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim<TKey>
{
// Summary:
// Constructor
public IdentityUser();
// Summary:
// Used to record failures for the purposes of lockout
public virtual int AccessFailedCount { get; set; }
//
// Summary:
// Navigation property for user claims
public virtual ICollection<TClaim> Claims { get; }
//
// Summary:
// Email
public virtual string Email { get; set; }
//
// Summary:
// True if the email is confirmed, default is false
public virtual bool EmailConfirmed { get; set; }
//
// Summary:
// User ID (Primary Key)
public virtual TKey Id { get; set; }
//
// Summary:
// Is lockout enabled for this user
public virtual bool LockoutEnabled { get; set; }
//
// Summary:
// DateTime in UTC when lockout ends, any time in the past is considered not
// locked out.
public virtual DateTime? LockoutEndDateUtc { get; set; }
//
// Summary:
// Navigation property for user logins
public virtual ICollection<TLogin> Logins { get; }
//
// Summary:
// The salted/hashed form of the user password
public virtual string PasswordHash { get; set; }
//
// Summary:
// PhoneNumber for the user
public virtual string PhoneNumber { get; set; }
//
// Summary:
// True if the phone number is confirmed, default is false
public virtual bool PhoneNumberConfirmed { get; set; }
//
// Summary:
// Navigation property for user roles
public virtual ICollection<TRole> Roles { get; }
//
// Summary:
// A random value that should change whenever a users credentials have changed
// (password changed, login removed)
public virtual string SecurityStamp { get; set; }
//
// Summary:
// Is two factor enabled for the user
public virtual bool TwoFactorEnabled { get; set; }
//
// Summary:
// User name
public virtual string UserName { get; set; }
}
其實你可以,只需在你的上下文類的OnModelCreating
上配置你的實體。
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<IdentityUser>().Ignore(u => u.AccessFailedCount);
//and so on...
}
或者,如果你的應用程序爲每個配置一個單獨的文件(至極是我推薦),你可以這樣做:
public class ApplicationUserEntityTypeConfiguration : EntityTypeConfiguration<ApplicationUser>
{
public ApplicationUserEntityTypeConfiguration()
{
Ignore(p => p.AccessFailedCount);
//And so on..
}
}
當我要添加遷移時拋出異常 – 2016-07-01 12:50:28
其實你可以忽略的字段,只是你需要你的上下文類中配置實體OnModelCreating爲:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>().Ignore(c => c.AccessFailedCount)
.Ignore(c=> c.LockoutEnabled)
.Ignore(c=>c.LockoutEndDateUtc)
.Ignore(c=>c.Roles)
.Ignore(c=>c.TwoFactorEnabled);//and so on...
modelBuilder.Entity<IdentityUser>().ToTable("Users");//to change the name of table.
}
你可能不需要這些VAL你是否確定asp.net不需要它們正常工作? – 2014-08-29 00:17:43
我意識到可以有一些關係,我已經編輯我的問題 – exeq 2014-08-29 00:29:41
如果你想要自己定製表格,那就不要使用Identity.Entityframework' – Shoe 2014-08-29 00:54:56