我使用实体框架创建了一个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