【发布时间】:2019-07-23 14:35:11
【问题描述】:
我正在使用 Net Core 2.2 和实体框架。我有一个 ApplicationUser 类,用于多种用户类型,外键相互连接,但实体框架在添加迁移时出错:
Unable to determine the relationship represented by navigation property 'ApplicationUser.Class' of type 'Class'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
我不确定实现此功能的正确方法是什么。谁能帮我?
我的 ApplicationUser 类:
public class ApplicationUser : IdentityUser
{
public string CustomerId { get; set; }
public string TeacherId { get; set; }
public int? ClassId { get; set; }
public int? SettingsId { get; set; }
public virtual ApplicationUser Customer { get; set; }
public virtual ApplicationUser Teacher { get; set; }
public virtual Class Class { get; set; }
public virtual Settings Settings { get; set; }
public virtual ICollection<Class> Classes { get; set; }
public virtual ICollection<License> Licenses { get; set; }
public virtual ICollection<Exercise> Exercises { get; set; }
public virtual ICollection<GameProgress> GameProgresses { get; set; }
public virtual ICollection<StudentExercise> StudentExercises { get; set; }
}
而且因为它在错误中,我的 Class 类:
public class Class
{
public int Id { get; set; }
public string TeacherId { get; set; }
public int? SettingsId { get; set; }
public virtual ApplicationUser Teacher { get; set; }
public virtual Settings Setting { get; set; }
public virtual ICollection<Exercise> Exercises { get; set; }
public virtual ICollection<ApplicationUser> Students { get; set; }
}
【问题讨论】:
标签: entity-framework asp.net-core