entity framework:SqlGeography与DbGeography
这两个对象在Microsoft SQL数据库中表示相同Geography数据类型的区别或预期目的是什么?
System.Data.Entity.Spatial.DbGeography
和
Microsoft.SqlServer.Types.SqlGeography
它们不能在彼此之间进行转换,但是在创建点,多边形等时, SqlGeography
还有其他命令。
我认为System.Data.Entity
仅用于Entity Framework,而Microsoft.SqlServer
是直接使用SqlCommand
时使用的?
你是对的,实质上就是这么简单。 DbGeography只是SqlGeography的一个愚蠢版本,旨在在Entity Framework中工作 。 SqlGeography中最流行的方法已在其中实现,但正如你正确指出的那样,并非所有方法。
虽然这两种类型不能直接相互转换, 但在需要SqlGeography的附加function时,转换它们的过程相对简单。
例如:
SqlGeography geog1 = SqlGeography.STPolyFromText('', srid); SqlGeography geog2; DbGeography dbGeog; // SqlGeography to DbGeography dbGeog = DbGeography.FromText(geog1.ToString(), srid); // DbGeography to SqlGeography geog2 = SqlGeography.Parse(dbGeog.AsText());