基于声明的身份 – 在asp.net MVC5 EF6中使用流畅的api映射表?

我正在尝试将个人资料/会员信息添加到我的MVC5应用程序中并添加配置映射.

我收到以下错误消息:

my.Models.IdentityUserLogin: : EntityType ‘IdentityUserLogin’ has no
key defined. Define the key for this EntityType.

my.Models.IdentityUserRole: : EntityType ‘IdentityUserRole’ has no key
defined. Define the key for this EntityType.

IdentityUserLogins: EntityType: EntitySet ‘IdentityUserLogins’ is
based on type ‘IdentityUserLogin’ that has no keys defined.

IdentityUserRoles: EntityType: EntitySet ‘IdentityUserRoles’ is based
on type ‘IdentityUserRole’ that has no keys defined.

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());           
    }
}

解决方法

调用base.OnModelCreating(modelBuilder)并没有解决我的问题.

在VS2013-Preview,VS2013-RC和VS2013-RTM中,Microsoft.AspNet.Identity.EntityFramework的行为似乎不同.我正在使用RTM版本.

从IdentityUser继承之后,我不得不重新创建模型中的所有其他主键,使其工作:

public class ApplicationUser : IdentityUser
{
    public string displayName { get; set; }
}


public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext() : base("DefaultConnection") { }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId);
        modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id);
        modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId,r.UserId });
    }

(见Configuring/Mapping Properties and Types with the Fluent API)

我猜AspNet.Identity.EntityFramework的工作正在进行中,这将被修复(?)

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....