目前数据库关系如下所示:http://i.imgur.com/954gPnl.png
我有一个连接器表叫做“friendship”,它包含2个值和一个键ID。这张表描述了X和Y是朋友,但Y可能不会成为X的朋友。所以这是一种线性的东西。
我想在实体框架中建立同样的模型,但我总是失败,因为我遇到了这个错误:
我想在实体框架中建立同样的模型,但我总是失败,因为我遇到了这个错误:
我在EF中创建了两个表:可能会导致循环或多重级联路径。
class Friendship
{
[Key]
public int id { get; set; }
public int whoid { get; set; }
public int whomid { get; set; }
[ForeignKey("whoid")]
public virtual Person who { get; set; }
[ForeignKey("whomid")]
public virtual Person whom { get; set; }
}
class Person
{
[Key]
public int id { get; set; }
public string username { get; set; }
public string password { get; set; }
public string name { get; set;}
public string city { get; set; }
public string street { get; set; }
public string hnum { get; set; }
public string bday { get; set; }
[InverseProperty("who")]
public virtual List<Friendship> wholist { get; set; }
[InverseProperty("whom")]
public virtual List<Friendship> whomlist { get; set; }
}