What you must avoid in LINQ to SQL one to many associations
Last saturday I spent few hours trying to figure out the reason of a very annoying bug that was happening with my WCF Service, for several times if got the same error: “The underlying connection was closed: The connection was closed unexpectedly.”.
The root cause of this bug was a LINQ to SQL query in my WCF service that was retuning a large list of objects, I tried to set maxItemsInObjectGraph of dataContractSerializer, but with no success. My LINQ model contains some onetomany associations that was generating both child and parent properties, this setting was causing the generation of infinite number of object references in my LINQ resultset, after disabling the generation of child property of all onetomany associations the error gone.