错误:“Id字段是必需的。”在使用AspNet.Identity 2.0在数据库中注册新用户时

欢迎,

我在Asp.Net mvc应用程序中创建(注册)新用户时遇到了主题中提到的validation错误,我在我的自定义ApplicationUser类中使用了Asp.Net Identity

public class ApplicationUser : IdentityUser { public async Task GenerateUserIdentityAsync(ApplicationUserManager manager) { var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); return userIdentity; } public virtual string EmailConfirmedChar { get; set; } public virtual string PhoneNumberConfirmedChar { get; set; } public virtual string TwoFactorEnabledChar { get; set; } public virtual string LockoutEnabledChar { get; set; } } 

我的TKey是字符串,所以我希望Id默认为Guid

当然我实现了我的自定义UserStore,UserManager等,一般来说我的灵感来自博客文章使用Entity Framework Fluent API定制ASP.NET身份数据模型

我做错了什么? 下载此博客文章中附带的示例时,通常会出现相同的validation错误。

相关或不,我使用Firebird数据库。

IdentityUser类在创建新实例时会自动生成GUID。 不是 IdentityUser class。 但是,您可以通过在ApplicationUser类构造函数中生成新的GUID来轻松解决此问题:

 public class ApplicationUser : IdentityUser { public ApplicationUser() { Id = Guid.NewGuid().ToString(); } // rest of code }