开发者

Linq2Sql Entity class cannot be serialized after adding an association

I am making ajax calls t开发者_JS百科o my webservice (using MS ajax framework - Telerik comps uses it actually). I am returning one of the Entity classes generated by the dbml. It used to work fine, but when I added the associations it started throwing an exception on the server, saying "a circular reference was detecting when serializing type "

I worked around it for now, but I'd really like to know what is happening. Thanks


This is because the relation is mapped with navigation properties both ways. ie you can use:

myCustomer.Orders

but also

order.Customer

You could try marking one of them non-public in the dbml, then if you need a public property, create it in the partial class, so you can mark the property with XmlIgnoreAttribute:

partial class Order
{
    [XmlIgnore]
    public Customer Customer
    {
        get { return InternalCustomer; }
        set { InternalCustomer = value; }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜