C# 在代码优先EF6中使用SqlGeography不生成列

C# 在代码优先EF6中使用SqlGeography不生成列,c#,visual-studio-2013,asp.net-mvc-5,entity-framework-6,C#,Visual Studio 2013,Asp.net Mvc 5,Entity Framework 6,我使用的是VS2013、.NET4.5、EF6、MVC5,MSSQL服务器是11.00.2100 当我在模型中创建一个名为: public SqlGeography Position { get; set; } 然后使用更新数据库不更改该模型的数据库表 我正在使用此参考中的SqlGeography: Microsoft.SqlServer.Types.SqlGeography 如何解决此问题?您需要使用EF中的DbGeography类型,然后Sql Server提供程序将其转换为SqlGeog

我使用的是VS2013、.NET4.5、EF6、MVC5,MSSQL服务器是11.00.2100

当我在模型中创建一个名为:

public SqlGeography Position { get; set; }
然后使用更新数据库不更改该模型的数据库表

我正在使用此参考中的SqlGeography:

Microsoft.SqlServer.Types.SqlGeography


如何解决此问题?

您需要使用EF中的
DbGeography
类型,然后Sql Server提供程序将其转换为
SqlGeography

因此,如果以后我想对SqlGeography执行任何操作,我可以将SqlGeography强制转换为DbGeography对象,或者DbGeography是中SqlGeography的LINQ等价物吗MVC5型号?不,您甚至没有SqlGeography类型。DBGeography是空间类型的EF抽象,而SqlGeography是实际实现。由于EF可以处理不同的数据库,所以它不公开本机数据库类型。AFAIR如果要使用空间类型,只需使用DBGeopography/DbGeometry类型公开的方法。