Entity Framework: SqlGeography vs DbGeography

c# entity-framework spatial sql-server


What distinguishes these two objects, which in a Microsoft SQL Database reflect the same geography datatype, or what is their intended use?




They cannot be placed together, yetSqlGeography has more control over producing points, polygons, etc.

I believe thatSystem.Data.Entity is solely intended for usage with Entity Framework, whereasMicrosoft.SqlServer used in conjunction with theSqlCommand directly rather?

4/20/2014 7:45:41 PM

Accepted Answer

You're right; it really is that easy. Simply put, the DbGeography is a SqlGeography that has been simplified in order to fit within the Enterprise Framework. Although not all of SqlGeography's methods have been implemented, you correctly point out that the majority have.

Although the two types cannot be cast directly into one another, doing so is a very straightforward process when the extra functionality of SqlGeography is needed.

For instance:

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());
3/14/2016 5:28:29 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow