【发布时间】:2015-11-08 21:30:19
【问题描述】:
我有这个:
public class Match
{
[Key]
public string Id { get; set; }
[ForeignKey("MatchedUser1")]
public string IdOf1 { get; set; }
[ForeignKey("MatchedUser2")]
public string IdOf2 { get; set; }
[InverseProperty("User1")]
public virtual ApplicationUser MatchedUser1 { get; set; }
[InverseProperty("User2")]
public virtual ApplicationUser MatchedUser2 { get; set; }
public List<ApplicationUser> User1 { get; set; }
public List<ApplicationUser> User2 { get; set; }
public virtual ApplicationUser User { get; set; }
}
这个想法是有一个包含 2 个用户作为外键的表(匹配)。
当我尝试添加迁移时,控制台回复:
“类型上的属性 'MatchedUser1' 的 InversePropertyAttribute “H4L.Web.Models.Match”无效。属性“User1”不是 相关类型的有效导航属性 'H4L.Web.Models.ApplicationUser'。确保该属性存在并且 是一个有效的引用或集合导航属性。”
而且我不想使用 fluent API,除非它是唯一的方法。
【问题讨论】:
标签: c# entity-framework model-view-controller code-first