我正在尝试将配置文件/成员身份信息添加到我的MVC5应用程序中并添加配置映射.
我收到以下错误消息:
my.Models.IdentityUserLogin :: EntityType'IdentityUserLogin'没有定义键.定义此EntityType的键.
my.Models.IdentityUserRole :: EntityType'IdentityUserRole'没有定义键.定义此EntityType的键.
IdentityUserLogins:EntityType:EntitySet'IdentityUserLogins'基于没有定义键的类型'IdentityUserLogin'.
IdentityUserRoles:EntityType:EntitySet'IdentityUserRoles'基于类型'IdentityUserRole',没有定义键.
public class ApplicationUser : IdentityUser
{
public string City { get; set; }
public string Discriminator { get; set; }
public string Address { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new ApplicationUserConfiguration());
}
}
Run Code Online (Sandbox Code Playgroud) 我一直想为我的集合类型创建导航属性,我发现这个例子中的一个人如何完成它使用OnModelCreating.我在我的MVC 5应用程序中试了一下,在尝试更新我的数据库时收到了这个错误:
在模型生成期间检测到一个或多个验证错误:
BlogEngine.Models.IdentityUserLogin :: EntityType'IdentityUserLogin'没有定义键.定义此EntityType的键.BlogEngine.Models.IdentityUserRole :: EntityType'IdentityUserRole'没有定义键.定义此EntityType的键.IdentityUserLogins:EntityType:EntitySet'IdentityUserLogins'基于没有定义键的类型'IdentityUserLogin'.IdentityUserRoles:EntityType:EntitySet'IdentityUserRoles'基于类型'IdentityUserRole',没有定义键.
我做了一些搜索,我找到了解决一个用户问题的解决方案,但他的需求与我的不同.对于我想要做的事情,解决方案似乎很复杂.
这是导致问题的代码:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
//public DbSet<Image> Images { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public DbSet<Post> Posts { get; set; }
public DbSet<Image> Images { get; set; }
public DbSet<Album> Albums { get; set; }
public DbSet<Tag> Tags { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder) …Run Code Online (Sandbox Code Playgroud) c# ×1