What is the difference, or intended purpose of these two object that represent the same Geography datatype in a Microsoft SQL Database?
System.Data.Entity.Spatial.DbGeography
and
Microsoft.SqlServer.Types.SqlGeography
They can't be cast between each other, but SqlGeography
has additional command when it comes to creating points, polygons etc.
I'm thinking that System.Data.Entity
is for use with Entity Framework only, whilst Microsoft.SqlServer
is for use when using the SqlCommand
directly instead?
You're right, in essence it is that simple. DbGeography is just a dumbed down version of SqlGeography, designed to work within the Entity Framework. The most popular methods of SqlGeography have been implemented within it but as you rightly point out, not all.
Whilst the two types cannot be directly cast between each other, the process of converting them is relatively simple in times where the additional functionality of SqlGeography is required.
For example:
SqlGeography geog1 = SqlGeography.STPolyFromText('<coords>', srid);
SqlGeography geog2;
DbGeography dbGeog;
// SqlGeography to DbGeography
dbGeog = DbGeography.FromText(geog1.ToString(), srid);
// DbGeography to SqlGeography
geog2 = SqlGeography.Parse(dbGeog.AsText());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With