Dapper SqlGeography error

本文关键字:error SqlGeography Dapper | 更新日期: 2023-09-27 18:26:30

当我尝试选择一个名为zones2的POCO时,Dapper出现错误。

public partial class ZONES2
{
    public int ID { get; set; }
    public SqlGeography LATLNG { get; set; }
}

此代码会产生错误。

  using (SqlConnection conn = new SqlConnection(connStr))
  {
     var zones = conn.Query<ZONES2>("select id,latlng from zones2");
  }

错误为:

System.Data.DataException was unhandled

HResult=-2146223087消息=分析列1时出错(latlng=POLYGON((50.804687175845011-1.1351966857910156,50.803927780711625-1.1324286460876465,50.804531229637192-1.1276113986968994,50.804870242468276-1.1231803894042969,50.8037379299972-1.1219358444213867,50.80011705805952-1.1197042465209961,50.796767162631618-1.1166036128997803,50.793932448170736-1.1145973205566406,50.79183003693492-1.1151659488677979,50.7920199360792-1.1166250705718994,50.789123891025056-1.1191999912261963、50.790316143034808-1.1227444584776549、50.790744884457638-1.1259269714355469、50.791687612108106-1.127171516418457、50.793932448170736-1.1280298233032227、50.794217283709372-1.128898590240479、50.794786949579219-1.1292421817779541、50.795675343209147-1.1292743682861328、50.79740822452452452-1.12932578323452、50.797587705782-1.1320317979153444,50.797784362743926-1.1328577995300293、50.79778432743926-1.1339521408081055、50.79802269251892-1.135221529627079、50.799967877542073-1.1342954635620117、50.801562477015025-1.1342542270608647、50.804687175845011-1.1351966857910156、50.80468 7175845011-1.1351966857910156)-对象)来源=DapperStackTrace:在D:''Dev''Dapper dot-net''Dapper NET40''SqlMapper.cs:line 4153中的Dapper.SqlMapper.SthrowDataException(Exception ex,Int32索引,IDataReader读取器,对象值)位于Deserialize0c167990-8477-4066-b090-cd522cbf0768(IDataReader)在Dapper.SqlMapper.d_61 1.MoveNext() in D:'Dev'dapper-dot-net'Dapper NET40'SqlMapper.cs:line 1608 at System.Collections.Generic.List 1..ctor(IEnumerable 1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable 1源)在D:''Dev''Dapper dot-net''Dapper NET40''SqlMapper.cs:line 1479中的Dapper.SqlMapper.Query[T](IDbConnection cnn,String sql,Object param,IDbTransaction transaction,布尔缓冲,可为空的1 commandTimeout, Nullable 1 commandType)空间。c:''users''paul''Google Drive''Visual Studio 2015''spacespace''space''Program.cs:line 17中的Program.Main(String[]args)位于System.AppDomain_nExecuteAssembly(RuntimeAssembly程序集,String[]参数)位于System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String[]args)位于Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()位于System.Threading.ThreadHelper.ThreadStart_Context(对象状态)位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔值preserveSyncCtx)在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,Object state,Boolean preserveSyncCtx)在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态)位于System.Threading.ThreadHelper.ThreadStart()内部异常:HResult=-2147467262消息=[A]Microsoft.SqlServer.Types.SqlGeography无法强制转换为[B]Microsoft.SqlServer.Types.SqlGeography。类型A源自"Microsoft.SqlServer.Types,Version=10.0.0,Culture=neutral,PublicKeyToken=88945dcd8080cc91',位于上下文"Default"中,位置为"C:''WINDOWS''assembly''GAC_MSIL''Microsoft.SqlServer.Types''10.0.0.0''__89845dcd8080cc91''Microsoft.SqlServer.Types.dll"。类型B源自"Microsoft.SqlServer.Types,Version=11.0.0.0,Culture=neutral,PublicKeyToken=89845dcd8080cc91',位于上下文"Default"中,位置为"C:''WINDOWS''assembly''GAC_MSIL''Microsoft.SqlServer.Types''11.0.0.0__89845dcd 8080cc91 ''Microsoft.SqlServer.Types.dll"。Source=匿名托管的DynamicMethods程序集StackTrace:位于Deserialize0c167990-8477-4066-b090-cd522cbf0768(IDataReader)内部异常:

然而,当我尝试这个代码时,它运行正常。(N.B.动态类型)

     using (SqlConnection conn = new SqlConnection(connStr))
     {
         var zones = conn.Query<dynamic>("select id,latlng from zones2");
     }

我想知道为什么我在第一个代码中出现错误?

Dapper SqlGeography error

我突出显示了对Microsoft.SqlServer的引用。Types打开了属性窗口,并将"使用特定版本"从true更改为false。我现在没有收到错误。