數據庫關係看起來像這樣的時刻: http://i.imgur.com/954gPnl.pngC#實體框架 - 初學者
我有所謂的友情連接器表,其中包含2個值和密鑰ID。這個表格描述X個朋友Y,但是Y可能不是朋友X.所以這是某種線性的東西。
我想模擬實體框架一樣,但我不能所有的時間,因爲我得到這個錯誤:
may cause cycles or multiple cascade paths.
我在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; }
}
看看這個:http://stackoverflow.com/questions/26930715/entity-framework-code-first-how-to-map-multiple-self-referencing-many-to-many-r – jlvaquero