I went back to the "drawing board" on a post I had written earlier concerning a StackOverflowException while trying to serialize an EF STE object graph... After failing to successfully adjust the stack size in IIS7, as described here, I decided to go down the path of looking into the the root cause...
I believe it has to do with the way the EF model has been designed.
Simplified, I have a Parent entity and a Child entity. The Child entity has two navigation properties back to Parent, e.g. Child.Parent and Child.ParentUsed. Naturally, the parent has two Child collections.
After looking closer at the data that causes the StackOverflow exception, I noticed there are several cycles in this object graph. I can't prove it, but I'm fairly positive that the cycles are causing this StackOverflow exception.
If I remove the data this table in the database, the problem goes away, but I won't be able to remove the records on the customer's machine. Bad design or not, I have to work around this at the EF level somehow.
What are my options to rework this? If my Child object didn't have navigation properties back to the parent, but instead had two int Fks, I wonder if there would be cycles that caused the serialization to choke? Is there a way to change navigation properties to Fks on one entity?
Thanks!
Update:
Removing both of the child's navigation properties back to the parent resolves this issue. I don't think it's necessarily a cycles issue, but perhaps the stack is exhausted trying to check for references and determine cycles.
I don't necessarily want to remove the nav properties. They are useful on the client. Is there a better way to fix this? Custom serialization?