【问题标题】:ASP.NET MVC5 EF6 Relation with ApplicationUserASP.NET MVC5 EF6 与 ApplicationUser 的关系
【发布时间】:2015-07-21 02:25:24
【问题描述】:
[ForeignKey("Creator")]
public string CreatorID {get;set;}
public virtual ApplicationUser Creator {get;set;}

我有一个模型,我想保存创建者和修改器。 但是迁移过程中出现错误

TSRDTEST.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.

TSRDTEST.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.

我正在使用内置的登录/注销/注册模板,数据库列前缀为“AspNet”,有没有办法在不修改整个项目项目的情况下修复该错误并保留前缀为 AspNet 的列,谢谢

【问题讨论】:

  • 这几乎读起来像俳句。您能否重新表述问题以使其更具可读性?
  • 已更新,请您再看一遍,谢谢。
  • 你有两个 DbContext 吗?例如ApplicationContext(默认情况下在您创建 ASP.NET MVC 项目时存在)和您创建的另一个 DbContext。
  • 公共类 ApplicationDbContext : IdentityDbContext ,公共类 DefaultConnection : DbContext 二,对!

标签: asp.net-mvc entity-framework asp.net-mvc-5 entity-framework-6 asp.net-identity-2


【解决方案1】:

其实我不明白你想做什么。但是实体之间的映射应该是这样的。

    public string CreatorID {get;set;}
    [ForeignKey("CreatorID ")]
    public virtual ApplicationUser Creator {get;set;}

【讨论】:

    猜你喜欢
    • 2015-09-12
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    相关资源
    最近更新 更多