我是实体框架的新手,即使我知道如何在 Merise 中做到这一点,我也无法先使用代码来做到这一点。
在实体用户中,我应该有一个外键“Promotion_Id”
在实体促销中,我应该有一个指向用户实体的外键“Pilote_Id”。
事情是这样的:我还有一个促销列表,它是促销中所有用户的列表。Pilote_Id 是该编队飞行员的 Id,他当然是用户。
我尝试了以下内容:
public class User : EntityWithId
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string Phone { get; set; }
public virtual Promotion Promotion { get; set; }
}
public class Promotion : EntityWithNameAndId
{
//Site is another entity, the place where the promotion is
public virtual Site Site { get; set; }
public List<User> Users { get; set; }
public virtual User Pilote { get; set; }
}
(注意:EntityWithId 仅包含一个 Id,而 EntityWithNameAndId 继承自 EntityWithId,仅包含一个名称)
但它只会导致在名为 Promotion_Id 和 Promotion_Id1 的用户中有 2 个外键。
我已经通过改变让整个事情都成功了
public virtual User Pilote { get; set; }
和
public virtual Guid PiloteId { get; set; }
但是我希望我的实体有一些一致性,所以..有没有正确的方法来实现这个?
慕妹3242003
相关分类