I’m trying to return from MVC 4 web api ApiController objects generated from entity framework 4 edmx, with accept:json/application.
The problem is json formatter returns also the Navigation Properties, which I don’t want to return (I want to return only the Primitive Properties).
So I’ve looked in the entity framework 4 code generated, in the Navigation Properties, and there are only XmlIgnoreAttribute and SoapIgnoreAttribute while I need JsonIgnoreAttribute.
I cannot change the code generated because it will be overwritten in the next change to the edmx,
so how can I configure that the model generation will be produced with JsonIgnoreAttribute?
Thank you
Ok, I found out what to do.
We need to use custom DefaultContractResolver in this way:
and in Global.asax:
and don’t worry about performance, as CreateProperties will only be called once for every type for the whole application duration 🙂