EDM4与POCO x WebService [英] EDM4 with POCO x WebService

查看:119
本文介绍了EDM4与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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆