I have a DB First Entity Framework 5 Data Access Layer that is mapped to a table containing a SQL geometry type field called CenterCoordinate. The resulting entity contains this:
public System.Data.Spatial.DbGeometry CenterCoordinate { get; set; }
My client javascript requests the API and only accepts JSON. I then use the Asp.net Web API to serve this using the default formatter (JSON.NET). In the API controller the field has a long list of properties including an XCoordinate and a YCoordinate.
In the client the JSON only contains this:
Geometry: Object CoordinateSystemId: 3498 WellKnownBinary: null WellKnownText: "POINT (6438089.715 1801515.828)"
I really don't want to have to parse out the WellKnownText to get to the values of X and Y.
So the question is how can I control the serialisation/de-serialisation of System.Data.Spatial types to/from JSON such that I get something more useful? How does the JSON.net formatter know what to include/exclude?
Note: I really don't want decorate the entity with attributes as these will be lost each time I regenerate the model from the database (I have no idea why we can't add attributes to model fields through VS2012 and have it remember them after a regeneration). So can this be with partial classes or overriding the formatter?
Thanks, Matt