当我尝试选择一个名为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 unhandledHResult=-2146233087 Message=Error解析列1 (latlng=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.7967671631631618 -1.1166036128997803,50.793932448170736 -1.1145973205566406,50.791830036934492 -1.115161659488677979,50.79201993602792 -1.116166250705718994,50.789123891025056 -1.1191999999261963,50.907163034808 -1.1227444584776549,50.79074844884457638-1.11516926735569,16178177106-1217410650.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.13395214080855,50.79802269251892 -1.1352215292627079,50.799967877542073 -1.1342954635620117,50.801562477015025 -1.134254227060847,50.804687175845011 -1.1351966857910156,50.804687175845011 -1.13519657910156)-) Source=Dapper StackTrace: at Dapper.SqlMapper.ThrowDataException( ex,Int32索引,IDataReader,阅读器)对象值)位于D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 4153 (位于Deserialize0c167990-8477-4066-b090-cd522cbf0768(IDataReader )位于Dapper.SqlMapper.d__611.MoveNext() in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1608 at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1源)位于D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1479位于spacial.Program.Main(String[] args)位于c:\users\paul\System.AppDomain._nExecuteAssembly(RuntimeAssembly大会上的Google Drive\Visual Studio 2015\spacial\spacial\Program.cs:line 17,在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object状态) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态,Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态,Boolean preserveSyncCtx) ) at System.Threading.ExecutionContext.Run(ExecutionContext preserveSyncCtx,ContextCallback callback,对象状态) Message=AMicrosoft.SqlServer.Types.SqlGeography :System.Threading.ThreadHelper.ThreadStart=-2147467262 InnerException不能强制转换为BMicrosoft.SqlServer.Types.SqlGeography。类型A源自位于位置'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SqlServer.Types\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll'.的上下文'Default‘中的'Microsoft.SqlServer.Types,Version=10.0.0.0,Culture=neutral,PublicKeyToken=89845dcd8080cc91类型B源自位于位置'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SqlServer.Types\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll'.的上下文'Default‘中的'Microsoft.SqlServer.Types,Version=11.0.0.0,Culture=neutral,PublicKeyToken=89845dcd8080cc91Deserialize0c167990-8477-4066-b090-cd522cbf0768(IDataReader上的Source=Anonymously Hosted DynamicMethods组装StackTrace: InnerException:
然而,当我尝试这段代码时,它运行正常。(注:动态类型)
using (SqlConnection conn = new SqlConnection(connStr))
{
var zones = conn.Query<dynamic>("select id,latlng from zones2");
}我想知道为什么我在第一个代码中得到一个错误?
发布于 2015-12-13 18:34:53
我突出显示了对Microsoft.SqlServer.Types的引用,打开了属性窗口,并将"Use specific version“从true更改为false。我现在没有得到一个错误。
https://stackoverflow.com/questions/34244485
复制相似问题