I have a database with a lots of relationships between Tables
and a Silverlight
client that connects to my server with WCF service
on ASP.Net
side.
First i used LINQ to SQL
as a robust mapper tables to object and in a WebMethod
that returns a List<Foo>
of my Database's object(suppose GetFoo()
). The Foo
has lots of relationships with other objects that each of that have lots of realaships too,(this means , there is a PK and FK between tables).also i use Microsoft Service Trace Viewr
for track my service
When i call GetFoo() , WCF returns this error:
Object graph for type 'X.Y.Z' contains cycles and cannot be serialized if reference tracking is disabled
I searched this error and find this great post but that is not working properly and i see same error too.
I know this is an old question now, but did you try decorating the classes generated by your DBML with [DataContract(IsReference=True)]?
I had the same problem in 2010 and had to resort to some fairly extreme measures to get it to work on client and service sides, but recently went back through it with VS2013/.NET 4.5 and had much less pain, as documented here (with EF v6 RC 1 POCO objects): http://sanderstechnology.com/2013/more-with-the-entity-framework-v6-rc1/12423/
A bit late this. But if anyone are using linqtosql and have this problem you can simply just open the tables in your dbml class. Right click next to a table and click properties. HEre there is a property named Serialization Mode.. Set it to Unidirectional
The error will be gone
Various options:
I'd vote firmly in the "DTO model" category; simply, having a separate model means you are less likely to run into tangles whenever you tweak the DB - and you are in complete control over it.