簡體   English   中英

Dapper SqlGeography錯誤

[英]Dapper SqlGeography error

嘗試選擇名為zone2的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 = -2146233087消息=錯誤解析柱1(經緯度= POLYGON((50.804687175845011 -1.1351966857910156,50.803927780711625 -1.1324286460876465,50.804531229637192 -1.1276113986968994,50.804870242468276 -1.1231803894042969,50.80373792999972 -1.1219358444213867,50.80011705805952 -1.1197042465209961,50.796767162631618 -1.1166036128997803,50.793932448170736 -1.1145973205566406,50.791830036934492 - 1.1151659488677979,50.79201993602792 -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.1288988590240479,50.794786949579219 -1.1292421817779541,50.795675343209147 -1.1292743682861328,50.797408224520929 -1.129325783323452,50.797587705782 -1.1320316791534424,50.797784362743926 -1.1328577995300293, 50.797784362743926 -1.1339521408081055,50.79802269251892 -1.1352215292627079,50.799967877542073- 1.1342954635620117、50.801562477015025 -1.1342542270608647、50.804687175845011 -1.1351966857910156、50.804687175845011 -1.1351966857910156))-Object)Source = Dapper StackTrace:at Dapper.SqlMapper.ThrowDataException(異常,Int32索引,IDataReader閱讀器\\ Dev \\ Dev \\ Dev): dot-net \\ Dapper NET40 \\ SqlMapper.cs:Deserialize0c167990-8477-4066-b090-cd522cbf0768(IDataReader)位於Dapper.SqlMapper.d__61的第4153行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源),位於Dapper.SqlMapper.Query [T] (IDbConnection cnn,字符串sql,對象參數,IDbTransaction事務,布爾型緩沖,Nullable 1 commandTimeout, Nullable 1 commandType)位於spacial.Program中D:\\ Dev \\ dapper-dot-net \\ Dapper NET40 \\ SqlMapper.cs:line 1479中。系統中c:\\ users \\ paul \\ Google Drive \\ Visual Studio 2015 \\ spacial \\ spacial \\ Program.cs:line 17中的Main(String [] args) .AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args)在System.AppDomain.ExecuteAssembly(String assemblyFile,證據assemblySecurity,String [] args)在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()在System.Threading.ThreadHelper。 System.Threading.ExecutionContext.Run(ExecutionContext執行上下文,ContextCallback回調,對象狀態,布爾狀態保持同步Ctx)在System.Threading.ExecutionContext.RunInternal(ExecutionContext執行上下文,ContextCallback回調,對象狀態,布爾值saveSyncCtx)處的ThreadStart_Context(對象狀態)。 System.Threading.ThreadHelper.ThreadStart()處的Threading.ExecutionContext.Run(ExecutionContext執行上下文,ContextCallback回調,對象狀態)InnerException:HResult = -2147467262消息= [A] Microsoft.SqlServer.Types.SqlGeography無法轉換為[B] Microsoft.SqlServer.Types.SqlGeography。 類型A源自'Microsoft.SqlServer.Types,Version = 10.0.0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91'在上下文'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__89845dcd8080cc91 \\ Microsoft.SqlServer.Types.dll'。 源=匿名托管的DynamicMethods程序集StackTrace:Deserialize0c167990-8477-4066-b090-cd522cbf0768(IDataReader)InnerException:

但是,當我嘗試此代碼時,它運行正常(NB動態類型)

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

我想知道為什么我的第一個代碼出現錯誤?

我突出了對Microsoft.SqlServer.Types的引用,打開了屬性窗口,並將“使用特定版本”從true更改為false。 我現在沒有錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM