Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
453 views
Welcome To Ask or Share your Answers For Others

1 Answer

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());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...