我使用實體框架創建了一個WCF服務。實體框架:獲取相關實體
我有2個表:劇院和地點。地點作爲劇院中的外鍵。
我的方法:
public theater[] GetTheaters()
{
using (Entities context = new Entities())
{
return context.theater.ToArray();
}
}
我不得不刪除從「虛擬」關鍵字「公共虛擬局部性地區{獲取;集;}」在我的戲劇課。否則,我得到一個CommunicationException。
但是,當我這樣做,我讓我的劇場名單,但局部性空...
我怎樣才能得到當地?
感謝
我的模型類(我也有其他實體):
public partial class locality
{
public locality()
{
this.theater = new HashSet<theater>();
}
public int idLocality { get; set; }
public int npa { get; set; }
public string locality1 { get; set; }
public ICollection<theater> theater { get; set; }
}
public partial class theater
{
public theater()
{
this.session = new HashSet<session>();
}
public int idTheater { get; set; }
public string name { get; set; }
public string address { get; set; }
public int idLocality { get; set; }
public double latitude { get; set; }
public double longitude { get; set; }
public int seats { get; set; }
public string phone { get; set; }
public string email { get; set; }
public bool threeD { get; set; }
public locality locality { get; set; }
public ICollection<session> session { get; set; }
}
以下是錯誤,我得到:
「對象圖表類型‘地方’包含週期和如果參考跟蹤被禁用無法序列
編輯:
我找到的解決方案:
在我所在的班級裏,我收藏了劇院。
我不得不添加 「私人像這樣的setter:
」 公共ICollection的劇場{獲得;私人設置; }」
所以它的工作原理,但我仍然有一個問題,我無法訪問從當地實體劇院了。(沒有更多的雙向)
爲您的模型類發佈更多代碼。您可能在該部分有問題 – Omar