WCF + Entity Framework + JSON = Tears

28 August 2012

Well, maybe not tears, but it probably won't work as smoothly as you want it to right out of the box. I had my nice little WCF with JSON responses all going nicely, with some test data, and that was all sweet, but the second I tried to return an EF object, WCF cried miserable, miserable tears and didn't return anything.

What's the deal? It turns out that the JSON serializer doesn't like the "IsReference" property which decorated my generated EF object, since there isn't a defined manner of handling cyclic references in JSON (or perhaps there is, but Microsoft hasn't gotten around to it yet).

I ended up copying my EF object to another object which I could control the DataContract for, but I've heard rumours of people swapping out the default serializer for something that does handle the IsReference property. Come across this combo of technologies before? Got any awesome tips? Does anyone know how to tell the EF generator that I don't want the IsReference property? I'd love to hear from you! :)

Tags: DataContract, EF, JSON, WCF

Add a Comment

No Comments