【发布时间】:2018-03-03 20:53:05
【问题描述】:
当我尝试注册用户或创建迁移时,我收到以下错误:
“无法在 'ApplicationUser' 上配置密钥,因为它是 派生类型。必须在根类型上配置密钥 '身份用户'。如果您不打算使用“IdentityUser” 包含在模型中,确保它不包含在 DbSet 中 上下文中的属性,在配置调用中引用 模型构建器,或从某个类型的导航属性中引用 包含在模型中。”
我有一个 BaseEntity,一切都来自这样:
public class BaseEntity
{
public int Id { get; set; }
[Required]
public DateTime DateCreated { get; set; }
[Required]
public DateTime DateModified { get; set; }
[Required]
public string CreatedById { get; set; }
[Required]
public string ModifiedById { get; set; }
public virtual IdentityUser CreatedBy { get; set; }
public virtual IdentityUser ModifiedBy { get; set; }
}
public class FilePath : BaseEntity, IAuditable
{
[StringLength(255)]
public string FileName { get; set; }
public FileType FileType { get; set; }
}
是否有新规则或更新表明您不能将 IdentityUser 用作导航属性? Google 并没有带来太多有用的信息。
整个解决方案是here 如果需要。
更新:升级到 2.0.1 预览版后,这些错误更有帮助:
外键属性 {'Id' : string} 的最佳匹配是 与主键 {'Id' : int} 不兼容。
【问题讨论】:
-
我认为您的意思是 2.1 预览版。相同的错误消息,但我使用脚手架从数据库构建模型。
-
incompatible消息我相信会消失,它只是info而不是错误。我想虽然你可能还有一个问题。 github.com/aspnet/EntityFrameworkCore/issues/10918
标签: asp.net asp.net-mvc entity-framework entity-framework-core