Hmm, it indeed is dropped somewhere.
[Test]
public void InsertOfSpatialValueTest()
{
var toInsert = new GeoTableEntity();
toInsert.Id = 1;
toInsert.Name = "Foo";
toInsert.GeometryCol = SqlGeometry.STGeomFromText(new SqlChars(new SqlString("LINESTRING (100 100, 20 180, 180 180)")), 0);
toInsert.GeographyCol = SqlGeography.STGeomFromText(new SqlChars(new SqlString("POINT(55.9271035250276 -3.29431266523898)")), 4931);
using(var adapter = new DataAccessAdapter())
{
try
{
Assert.IsTrue(adapter.SaveEntity(toInsert, true));
// fetch it back.
var inserted = adapter.FetchNewEntity<GeoTableEntity>(new RelationPredicateBucket(GeoTableFields.Id == 1));
Assert.AreEqual(1, inserted.Id);
Assert.AreEqual(toInsert.GeometryCol.ToString(), inserted.GeometryCol.ToString());
Assert.AreEqual(toInsert.GeographyCol.ToString(), inserted.GeographyCol.ToString());
// test in DTO projection too
var metaData = new LinqMetaData(adapter);
var results = metaData.GeoTable.Where(g => g.Id == 1).ProjectToGeoTable().ToList();
Assert.AreEqual(1, results.Count);
var dto = results[0];
Assert.AreEqual(1, dto.Id);
Assert.AreEqual(toInsert.GeometryCol.ToString(), dto.GeometryCol.ToString());
Assert.AreEqual(toInsert.GeographyCol.ToString(), dto.GeographyCol.ToString());
}
finally
{
adapter.DeleteEntity(toInsert);
}
}
}
However upon close examination, the string variant doesn't contain the SRID. There are a few weird things going on. If I fill in your SRID in the test, I get an exception that the sys table doesn't contain the SRID:
System.ArgumentException : 24204: The spatial reference identifier (SRID) is not valid. The specified SRID must match one of the supported SRIDs displayed in the sys.spatial_reference_systems catalog view.
at Microsoft.SqlServer.Types.SqlGeography.set_Srid(Int32 value)
at Microsoft.SqlServer.Types.SqlGeography..ctor(GeoData g, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
however it's not going to the db afaik, at least not over ADO.NET
Then, if I fill in a random SRID from the sys.spatial_reference_systems catalog view, and insert the row, the SRID changes in the column of the entity *that's inserted* after the query has been created! So after the insert, `toInsert.GeographyCol.SRID` is 4326, the default. But... the value isn't changed anywhere. This is due to the refetch after the insert, so it fetches the default back.
Tbh, I haven't found any other ways to insert the value other than using the full string representation with convert from the SRID embedded in the string.
Looking into what's going on with the SRID as it shouldn't change regardless.