实体框架:SqlGeography与DbGeography [英] Entity Framework: SqlGeography vs DbGeography

查看:368
本文介绍了实体框架:SqlGeography与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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆