实体框架:SqlGeography与DbGeography [英] Entity Framework: SqlGeography vs DbGeography
问题描述
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
System.Data.Entity.Spatial.DbGeography
和
Microsoft.SqlServer.Types.SqlGeography
它们不能彼此投射,但是在创建点,多边形等时, c $ c> SqlGeography 有额外的命令。
They can't be cast between each other, but SqlGeography
has additional command when it comes to creating points, polygons etc.
我认为 System.Data.Entity
仅用于实体框架,而 Microsoft.SqlServer
用于直接使用 SqlCommand
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?
推荐答案
你从右到右,实质上就是那么简单。 DbGeography 仅仅是一个倾斜版本的 SqlGeography ,旨在在实体框架中工作。 SqlGeography最流行的方法已经在其中实现,但正如您正确地指出的那样,而不是全部。
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.
虽然这两种类型之间不能直接相互转换,在需要 SqlGeography 的附加功能的时候,转换它们是相对简单的。
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.
例如:
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());
这篇关于实体框架:SqlGeography与DbGeography的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!