I've had this problem too. Its a bug apparently.
Either two choices here - drop down to EF5 for the old System.Data.Entity.DbGeography
(rather than System.Data.Entity.Spatial.DbGeography
), or wait until they patch it.
Edit: Its been a long time, and so far the only hack I've come up with is this as a way to write to the properties and hide the ugly serialised format (however still cannot query against it.
private bool hasSetLongitude = false;
private bool hasSetLatitiude = false;
private double? longitude = null;
private double? latitiude = null;
/// <summary>
/// Get or set the coordinates.
/// </summary>
[Column("engi_coord"), Required]
public DbGeography Coordinates { get; set; }
/// <summary>
/// Get or set the lang coordinates.
/// </summary>
[Column("engi_lng"), DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public double? Longitude
{
get
{
return this.Coordinates != null ? this.Coordinates.Longitude : (double?)null;
}
set
{
this.longitude = value;
this.hasSetLongitude = true;
if (this.hasSetLongitude)
{
if (this.longitude.HasValue &&
this.latitiude.HasValue)
{
this.Coordinates = DbGeography.PointFromText(string.Format("POINT({0} {1})", this.longitude.Value, this.latitiude.Value), 4326);
}
else
{
this.Coordinates = null;
}
}
}
}
/// <summary>
/// Get or set the lat coordinates.
/// </summary>
[Column("engi_lat"), DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public double? Latitude
{
get
{
return this.Coordinates != null ? this.Coordinates.Latitude : (double?)null;
}
set
{
this.latitiude = value;
this.hasSetLatitiude = true;
if (this.hasSetLatitiude)
{
if (this.longitude.HasValue &&
this.latitiude.HasValue)
{
this.Coordinates = DbGeography.PointFromText(string.Format("POINT({0} {1})", this.longitude.Value, this.latitiude.Value), 4326);
}
else
{
this.Coordinates = null;
}
}
}
}
Migrate to add the computed columns:
this.Sql("ALTER TABLE dbo.engi_engineer ADD engi_lng AS engi_coord.Long");
this.Sql("ALTER TABLE dbo.engi_engineer ADD engi_lat AS engi_coord.Lat");
Now ignore the coordinates property from API:
this.EntityType.Ignore(p => p.Coordinates);