sim*_*olo 13 c# sql-server entity-framework spatial
这两个对象在Microsoft SQL数据库中表示相同Geography数据类型的区别或预期目的是什么?
System.Data.Entity.Spatial.DbGeography
Run Code Online (Sandbox Code Playgroud)
和
Microsoft.SqlServer.Types.SqlGeography
Run Code Online (Sandbox Code Playgroud)
它们不能在彼此之间施放,但SqlGeography在创建点,多边形等时有额外的命令.
我认为这System.Data.Entity只是用于实体框架,而直接Microsoft.SqlServer使用是SqlCommand直接使用?
Jon*_*amy 12
你是对的,实质上就是这么简单. DbGeography只是SqlGeography的一个愚蠢版本,旨在在Entity Framework中工作.最流行的SqlGeography方法已在其中实现,但正如你正确指出的那样,并非全部.
虽然这两种类型之间不能直接相互转换,但在需要SqlGeography的附加功能时,转换它们的过程相对简单.
例如:
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());
Run Code Online (Sandbox Code Playgroud)