当我使用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