ServiceStack OrmLite无法检索SqlGeography字段

时间:2016-04-27 13:45:54

标签: sql-server servicestack ormlite-servicestack sqlgeography

我按照此处的说明使用ServiceStack OrmLite v.4.0.56的SqlGeography类型: https://github.com/ServiceStack/ServiceStack.OrmLite/wiki/SQL-Server-Types

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
SqlServerConverters.Configure(SqlServer2012Dialect.Provider);

(不是网络应用程序)

这是我的DataModel类:

[DataContract]
[Schema("dbo")]
public class BusinessEntity
{
    [DataMember, PrimaryKey, AutoIncrement]
    public Int16 BusinessEntityId { get; set; }
    ...
    [DataMember]
    public SqlGeography LatLong { get; set; }
}

当我使用OrmLite检索这些记录时,所有LatLong都为空,但数据库中有数据:

enter image description here

我的测试只是检索所有记录:

return Db.Select<DataModel.dbo.BusinessEntity>();

安装nuget包时看起来有错误,但是没有运行时错误(我在安装nuget包时始终遇到此错误):

  

尝试收集包的依赖关系信息   &#39; ServiceStack.OrmLite.SqlServer.Converters.4.0.56&#39;关于   project&#39; Services \ Web \ SO.Services.Data.Tests&#39;,定位   &#39; .NETFramework,版本= v4.6.1&#39;试图解决依赖关系   package&#39; ServiceStack.OrmLite.SqlServer.Converters.4.0.56&#39;同   DependencyBehavior&#39;最低&#39;解决安装包的操作   &#39; ServiceStack.OrmLite.SqlServer.Converters.4.0.56&#39;已解决的操作   安装包&#39; ServiceStack.OrmLite.SqlServer.Converters.4.0.56&#39;   Package&#39; Microsoft.SqlServer.Types.11.0.2&#39;已存在于文件夹中   &#39; C:\ Users \ cklepeis \ documents \ visual studio 2015 \ Projects \ SO \ packages&#39;   添加了包&#39; Microsoft.SqlServer.Types.11.0.2&#39; to&#39; packages.config&#39;   执行脚本文件&#39; C:\ Users \ cklepeis \ documents \ visual studio   2015年\ PROJECTS \ SO \包\ Microsoft.SqlServer.Types.11.0.2 \工具\ install.ps1&#39; ...   Where-Object:无法绑定参数&#39; FilterScript&#39;。无法转换   &#34;姓名&#34; type&#34; System.String&#34;的值输入&#34; S.   ystem.Management.Automation.ScriptBlock&#34 ;.在   C:\ Users \ cklepeis \ documents \ visual studio   2015年\ PROJECTS \ SO \包\ Microsoft.SqlServer.Types.11.0.2 \工具\ install.p   s1:11 char:50   + $ folderx86 = $ sqlServerTypes.ProjectItems |其中&lt;&lt;&lt;&lt;名称-eq&#34; x86&#34;       + CategoryInfo:InvalidArgument:(:) [Where-Object],ParameterBindingException       + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand   Where-Object:无法绑定参数&#39; FilterScript&#39;。无法转换   &#34;姓名&#34; type&#34; System.String&#34;的值输入&#34; S.   ystem.Management.Automation.ScriptBlock&#34 ;.在   C:\ Users \ cklepeis \ documents \ visual studio   2015年\ PROJECTS \ SO \包\ Microsoft.SqlServer.Types.11.0.2 \工具\ install.p   s1:17 char:50   + $ folderx64 = $ sqlServerTypes.ProjectItems |其中&lt;&lt;&lt;&lt;名称-eq&#34; x64&#34;       + CategoryInfo:InvalidArgument:(:) [Where-Object],ParameterBindingException       + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand   Where-Object:无法绑定参数&#39; FilterScript&#39;。无法转换   &#34;姓名&#34; type&#34; System.String&#34;的值输入&#34; S.   ystem.Management.Automation.ScriptBlock&#34 ;.在   C:\ Users \ cklepeis \ documents \ visual studio   2015年\ PROJECTS \ SO \包\ Microsoft.SqlServer.Types.11.0.2 \工具\ install.p   s1:23 char:46   + $ cppLinkx86 = $ folderx86.ProjectItems |其中&lt;&lt;&lt;&lt;名称-eq&#34; msvcr100.dll&#34;       + CategoryInfo:InvalidArgument:(:) [Where-Object],ParameterBindingException       + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand   Where-Object:无法绑定参数&#39; FilterScript&#39;。无法转换   &#34;姓名&#34; type&#34; System.String&#34;的值输入&#34; S.   ystem.Management.Automation.ScriptBlock&#34 ;.在   C:\ Users \ cklepeis \ documents \ visual studio   2015年\ PROJECTS \ SO \包\ Microsoft.SqlServer.Types.11.0.2 \工具\ install.p   s1:30 char:46   + $ sqlLinkx86 = $ folderx86.ProjectItems |其中&lt;&lt;&lt;&lt;名称-eq&#34; SqlServerSpatial110.dll&#34;       + CategoryInfo:InvalidArgument:(:) [Where-Object],ParameterBindingException       + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand   Where-Object:无法绑定参数&#39; FilterScript&#39;。无法转换   &#34;姓名&#34; type&#34; System.String&#34;的值输入&#34; S.   ystem.Management.Automation.ScriptBlock&#34 ;.在   C:\ Users \ cklepeis \ documents \ visual studio   2015年\ PROJECTS \ SO \包\ Microsoft.SqlServer.Types.11.0.2 \工具\ install.p   s1:37 char:46   + $ cppLinkx64 = $ folderx64.ProjectItems |其中&lt;&lt;&lt;&lt;名称-eq&#34; msvcr100.dll&#34;       + CategoryInfo:InvalidArgument:(:) [Where-Object],ParameterBindingException       + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand   Where-Object:无法绑定参数&#39; FilterScript&#39;。无法转换   &#34;姓名&#34; type&#34; System.String&#34;的值输入&#34; S.   ystem.Management.Automation.ScriptBlock&#34 ;.在   C:\ Users \ cklepeis \ documents \ visual studio   2015年\ PROJECTS \ SO \包\ Microsoft.SqlServer.Types.11.0.2 \工具\ install.p   s1:44 char:46   + $ sqlLinkx64 = $ folderx64.ProjectItems |其中&lt;&lt;&lt;&lt;名称-eq&#34; SqlServerSpatial110.dll&#34;       + CategoryInfo:InvalidArgument:(:) [Where-Object],ParameterBindingException       + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand

     

AutoHides:假标题:   Microsoft.SqlServer.Types集合:   {Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase,   Microsoft.VisualStudio.Platfo                           rm.WindowManagement.DTE.WindowBase,Microsoft.VisualStudio.Platform.WindowManagement.DTE.Window                           Base,Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase ...}   CommandBars:{URL工具栏,F1消歧工具栏}   ContextAttributes:System .__ ComObject DTE:   System .__ ComObject Document:HWnd:   6425562身高:1671 IsFloating:False   种类:工具左:1674可连接


  :False LinkedWindowFrame:   Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase   LinkedWindows:Object:System .__ ComObject   ObjectKind:{E8B06F52-6D01-11D2-AA7D-00C04F990343}项目   :ProjectItem:选择:顶部
  :283类型:vsWindowTypeToolWindow可见

  :真实宽度:1785 WindowState:   vsWindowStateMaximize HasBeenDeleted:False事件
  :Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowEvents   VisibilityEvents:   Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowVisibilityEvents   Rect:1674.0625,283.020833333333,1785,1671   OutstandingEventCount:0

     

已成功安装&#39; Microsoft.SqlServer.Types 11.0.2&#39;至   SO.Services.Data.Tests包   &#39; ServiceStack.OrmLite.SqlServer.Converters.4.0.56&#39;已存在于   文件夹&#39; C:\ Users \ cklepeis \ documents \ visual studio   2015 \项目\ SO \包&#39;添加包   &#39; ServiceStack.OrmLite.SqlServer.Converters.4.0.56&#39;至   &#39; packages.config&#39;成功安装   &#39; ServiceStack.OrmLite.SqlServer.Converters 4.0.56&#39;至   SO.Services.Data.Tests   ==========完成==========

1 个答案:

答案 0 :(得分:2)

我在安装ServiceStack.OrmLite.SqlServer.Converters NuGet包时没有遇到任何问题:

Attempting to gather dependencies information for package 'ServiceStack.OrmLite.SqlServer.Converters.4.0.56' with respect to project 'ConsoleApplication4', targeting '.NETFramework,Version=v4.5'
Attempting to resolve dependencies for package 'ServiceStack.OrmLite.SqlServer.Converters.4.0.56' with DependencyBehavior 'Lowest'
Resolving actions to install package 'ServiceStack.OrmLite.SqlServer.Converters.4.0.56'
Resolved actions to install package 'ServiceStack.OrmLite.SqlServer.Converters.4.0.56'
Adding package 'Microsoft.SqlServer.Types.11.0.2' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'Microsoft.SqlServer.Types.11.0.2' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'Microsoft.SqlServer.Types.11.0.2' to 'packages.config'
Executing script file 'C:\src\wip\ConsoleApplication4\packages\Microsoft.SqlServer.Types.11.0.2\tools\install.ps1'...


AutoHides             : False
Caption               : Microsoft.SqlServer.Types
Collection            : {Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase, 
                        Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase, 
                        Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase, 
                        Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase...}
CommandBars           : {URL Toolbar, F1 Disambiguation Toolbar}
ContextAttributes     : System.__ComObject
DTE                   : System.__ComObject
Document              : 
HWnd                  : 32967448
Height                : 1060
IsFloating            : False
Kind                  : Tool
Left                  : 74
Linkable              : False
LinkedWindowFrame     : Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase
LinkedWindows         : 
Object                : System.__ComObject
ObjectKind            : {E8B06F52-6D01-11D2-AA7D-00C04F990343}
Project               : 
ProjectItem           : 
Selection             : 
Top                   : 254
Type                  : vsWindowTypeToolWindow
Visible               : True
Width                 : 2357
WindowState           : vsWindowStateMaximize
HasBeenDeleted        : False
Events                : Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowEvents
VisibilityEvents      : Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowVisibilityEvents
Rect                  : 73.5,253.5,2357,1060
OutstandingEventCount : 0



Successfully installed 'Microsoft.SqlServer.Types 11.0.2' to ConsoleApplication4
Adding package 'ServiceStack.Interfaces.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.Interfaces.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.Interfaces.4.0.56' to 'packages.config'
Successfully installed 'ServiceStack.Interfaces 4.0.56' to ConsoleApplication4
Adding package 'ServiceStack.Text.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.Text.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.Text.4.0.56' to 'packages.config'
Successfully installed 'ServiceStack.Text 4.0.56' to ConsoleApplication4
Adding package 'ServiceStack.Common.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.Common.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.Common.4.0.56' to 'packages.config'
Successfully installed 'ServiceStack.Common 4.0.56' to ConsoleApplication4
Adding package 'ServiceStack.OrmLite.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.OrmLite.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.OrmLite.4.0.56' to 'packages.config'
Successfully installed 'ServiceStack.OrmLite 4.0.56' to ConsoleApplication4
Adding package 'ServiceStack.OrmLite.SqlServer.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.OrmLite.SqlServer.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.OrmLite.SqlServer.4.0.56' to 'packages.config'
Successfully installed 'ServiceStack.OrmLite.SqlServer 4.0.56' to ConsoleApplication4
Adding package 'ServiceStack.OrmLite.SqlServer.Converters.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.OrmLite.SqlServer.Converters.4.0.56' to folder 'C:\src\wip\ConsoleApplication4\packages'
Added package 'ServiceStack.OrmLite.SqlServer.Converters.4.0.56' to 'packages.config'
Successfully installed 'ServiceStack.OrmLite.SqlServer.Converters 4.0.56' to ConsoleApplication4
========== Finished ==========

如果这些安装问题仍然存在,您可以尝试删除您的NuGet /packages文件夹和clearing your NuGet cache,以便下次安装ServiceStack.OrmLite.SqlServer.Converters时,它会再次从NuGet重新下载所有软件包。

要使用特定于SQL Server的类型,您需要使用SqlServer2012Dialect.Provider并指定您在连接字符串上使用SQL Server 2012,例如:

SqlServerConverters.Configure(SqlServer2012Dialect.Provider);

var dbFactory = new OrmLiteConnectionFactory(
    "Server=localhost;Database=test;User Id=test;Password=test;Type System Version=SQL Server 2012",
    SqlServer2012Dialect.Provider);

然后您可以正常使用SQL Server特定类型,例如这个例子:

db.DropAndCreateTable<BusinessEntity>();

db.Insert(new BusinessEntity
{
    BusinessEntityId = 1,
    LatLong = SqlGeography.Point(40.6898329, -74.0452177, 4326)
});

db.Select<BusinessEntity>().PrintDump();

打印出已填充的SqlGeography记录:

[
        {
                BusinessEntityId: 1,
                LatLong:
                {
                        IsNull: False,
                        STSrid: 4326,
                        Lat: 40.6898329,
                        Long: -74.0452177,
                        Z: Null,
                        M: Null,
                        HasZ: False,
                        HasM: False
                }
        }
]