EDM4与POCO x WebService [英] EDM4 with POCO x WebService
问题描述
我对此代码有疑问:
我的班级:
公共班级人员()
{
私人名单<人员> _peopleparent = new List< People>();
public virtual int Id {get;组;公共虚拟字符串名称{get;组;公共虚拟int? ParentId {get;组;公共虚拟人父母{get;组;公共虚拟列表< People> PeopleParent
{
get {return _peopleparent; }集{_peopleparent = value;我的网络服务:公共类PeopleWS:System.Web.Services.WebService
{
ModelContext db = new ModelContext();
[WebMethod]
公共列表< People>选择所有()
{
返回(从db.People中的q选择q).ToList();
}
}
当我的错误执行webservice:
System.InvalidOperationException:生成XML文档时出错。 ---> System.InvalidOperationException:序列化PeopleWS.People类型的对象时检测到循环引用。
您可能需要归因于class - 例如
[
DataContractAttribute (IsReference = true )] 跨度>
I have a problem with this code:
My class:
public class People()
{
private List<People> _peopleparent = new List<People>();
public virtual int Id { get; set; };
public virtual string Name { get; set; }
public virtual int? ParentId { get; set; }
public virtual People Parent { get; set; }
public virtual List<People> PeopleParent
{
get { return _peopleparent; }
set { _peopleparent = value; }
}
}
My webservice:
public class PeopleWS : System.Web.Services.WebService
{
ModelContext db = new ModelContext();
[WebMethod]
public List<People> SelectAll()
{
return (from q in db.People select q).ToList();
}
}
The error when I execute the webservice:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: A circular reference was detected while serializing an object of type PeopleWS.People.
You may need to attribute your class - e.g.
[
DataContractAttribute(IsReference=true)]
这篇关于EDM4与POCO x WebService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!