Pav*_*bin 9 sql-server spatial .net-4.5 entity-framework-5
我有WCF REST服务,其中包含以下代码
var geo = DbGeography.PointFromText(string.Format("POINT({0} {1})", longitude, latitude), DbGeography.DefaultCoordinateSystemId);
Run Code Online (Sandbox Code Playgroud)
单元测试工作正常,但是当我从客户端或HTTP debuder调用此代码时,提供纬度和经度的任何值exept 0,它会失败,但异常:
"24141: A number is expected at position X of the input. The input has ,XXXXXX."
at Microsoft.SqlServer.Types.WellKnownTextReader.RecognizeDouble()
at Microsoft.SqlServer.Types.WellKnownTextReader.ParsePointText(Boolean parseParentheses)
at Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type)
at Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.ParseText(OpenGisType type, SqlChars taggedText, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.STPointFromText(SqlChars pointTaggedText, Int32 srid)
Run Code Online (Sandbox Code Playgroud)
latitude和longitute例如
lat:37.58336895 long:-122.40549454
lat:37.38931302 long:-122.16207476
我使用从SQLServer安装目录和SqlGeography.Point引用的Microsoft.SqlServer.Types来处理代码端的spartial数据.现在我想直接使用EF 5功能而不使用Microsoft.SqlServer.Types.无论有没有这个参考,都会失败.
知道什么是错的吗?
安装了.NET 4.5,SQL Server版本是Microsoft SQL Server 2008(SP3) - 10.0.5500.0(Intel X86)2011年9月22日00:28:06版权所有(c)1988-2008 Microsoft Corporation Standard Edition on Windows NT 6.1(Build 7601) :Service Pack 1)
Mar*_*oli 13
您必须在连接之前使用invariantCulture转换坐标.
String lon = longitude.ToString(CultureInfo.InvariantCulture);
String lat = latitude.ToString(CultureInfo.InvariantCulture);
var geo = DbGeography.PointFromText(string.Format("POINT({0} {1})", lon, lat), DbGeography.DefaultCoordinateSystemId);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4352 次 |
| 最近记录: |