0
我正在使用实体框架来构建我的数据库。我的模型包含两个实体:Entite
和ApplicationUser
(请参阅下面的代码)。实体框架错误:无法确定类型之间的关联主体端
有这些实体之间的两个关系:
- 一到多:一个
Entite
可以包含一个或多个用户。并且用户属于一个Entite
。 - 一对一:一个
Entite
必须有一个用户作为负责人和一个用户可以只负责一个Entite
。
Entite:
public class Entite : AuditableEntity<int>
{
[Required]
[MaxLength(10)]
public String code { get; set; }
[Required]
[MaxLength(50)]
public String Libelle { get; set; }
[Required]
[MaxLength(10)]
public String type { get; set; }
[Key, ForeignKey("ResponsableId")]
public int? ResponsableId { get; set; }
public virtual ApplicationUser responsable { get; set; }
public int? RattachementEntiteId { get; set; }
[Key, ForeignKey("RattachementEntiteId")]
public virtual Entite rattachement { get; set; }
public List<Entite> Children { get; set; }
}
ApplicationUser:
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Matricule { get; set; }
public DateTime? dateRecrutement { get; set; }
public int? entiteId { get; set; }
[ForeignKey("entiteId")]
public virtual Entite entite { get; set; }
}
当我尝试使用Add-Migration
命令来构建数据库,我得到这个错误:
无法确定类型之间关联的主要端点
有关此问题的任何想法?
感谢您的帮助