I am trying to insert DBGeography
type via ado.net but no luck.
This is the errors that I am getting:
No mapping exists from object type System.Data.Entity.Spatial.DbGeography to a known managed provider native type.
or:
Specified type is not registered on the target server.System.Data.Entity.Spatial.DbGeography, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
This is what I do when I am getting it from db and this works fine:
dynamic temp = reader.GetValue(3);
var text = string.Format("POINT({0:R} {1:R})", temp.Long, temp.Lat);
var srid = temp.STSrid.Value;
this.Coordinates = System.Data.Entity.Spatial.DbGeography.PointFromText(text, srid);
But insert doesn't work:
updateCommand.Parameters.AddWithValue("@Coordinates", store.Coordinates);
// or ...
SqlParameter p = new SqlParameter();
p.ParameterName = "@Coordinates";
p.Value = store.Coordinates;
p.SqlDbType = System.Data.SqlDbType.Udt;
p.UdtTypeName = "geography";
updateCommand.Parameters.Add(p);
What is wrong here?