当我尝试注册用户或创建迁移时,出现以下错误:
“无法在'ApplicationUser'上配置键,因为它是一个派生类型。必须在根类型'IdentityUser'上配置键。如果您不打算将'IdentityUser'包含在模型中,请确保它未包含在上下文中的DbSet属性中,在对ModelBuilder进行配置调用时引用,或者从包含在模型中的类型的导航属性中引用。”
我有一个所有内容都从中派生的BaseEntity,如下所示:
“无法在'ApplicationUser'上配置键,因为它是一个派生类型。必须在根类型'IdentityUser'上配置键。如果您不打算将'IdentityUser'包含在模型中,请确保它未包含在上下文中的DbSet属性中,在对ModelBuilder进行配置调用时引用,或者从包含在模型中的类型的导航属性中引用。”
我有一个所有内容都从中派生的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没有带来太多有用的信息。
整个解决方案在这里 如有需要。
更新:升级到2.0.1预览版后,错误信息更加详细:
外键属性{'Id' : string}的最佳匹配与主键{'Id' : int}不兼容。
incompatible
消息将会消失,它只是一个info
而不是错误。但我认为你可能还有其他问题。https://github.com/aspnet/EntityFrameworkCore/issues/10918 - Simon_Weaver