我按照这里的例子
https://docs.microsoft.com/en-us/ef/core/querying/related-data#lazy-loading
我的两个班级看起来像这样
public class RefMedSchool
{
public int Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public virtual ICollection<ApplicationUser> ApplicationUser { get; set; }
}
public class ApplicationUser : IdentityUser
{
public string UserFirstName { get; set; }
public string UserLastName { get; set; }
public bool MustChangePassword { get; set; }
public int? MedicalSpecialtyId { get; set; }
[ForeignKey("RefMedicalSpecialtyForeignKey")]
public RefMedicalSpecialty RefMedicalSpecialty { get; set; }
public int RefMedSchoolId { get; set; }
public virtual RefMedSchool RefMedSchool { get; set; }
public UserProfileData UserProfileData { get; set; }
public ICollection<UserFeedback> UserFeedbacks { get; set; }
public ICollection<UserAction> UserActions { get; set; }
public ICollection<UserProgram> UserPrograms { get; set; }
}
但是当试图创建数据库时,我收到以下错误。怎么了 ?这些属性根据需要是虚拟的。
System.InvalidOperationException:实体类型“ApplicationUser”上的“导航属性“RefMedicalSpecialty”不是虚拟的。UseLazyLoadingProxies 要求所有实体类型都是公共的、未密封的、具有虚拟导航属性并具有公共或受保护的构造函数。