简体   繁体   English

是否可以在使用 .NET 4.8 的 ASP.NET 应用程序中使用 SQL Server 2017 的 Geography 数据类型?

[英]Is it possible to use Geography data type of SQL Server 2017 in ASP.NET application using .NET 4.8?

I have not been able to configure to use database with Geography datatype in SQL Server 2017 in an ASP.NET application.我无法在 ASP.NET 应用程序中配置为在 SQL Server 2017 中使用具有Geography数据类型的数据库。

In my other question I have outlined various workarounds which do not work.在我的另一个问题中,我概述了各种不起作用的解决方法。 Link: SO Question链接: SO问题

Can anybody confirm successfully using Geography type in SQL Server 2017 in an ASP.NET application.任何人都可以在 ASP.NET 应用程序中成功使用 SQL Server 2017 中的Geography类型进行确认。 If yes, what is the configuration?如果是,配置是什么?

For the only workaround is converting geography data to string, and then deserializing it on the client, which is a horrible way to do things...唯一的解决方法是将geography数据转换为字符串,然后在客户端反序列化它,这是一种可怕的做事方式......

I use an OData v4 API in a solution that allows farmers to map their farms and paddocks and they can place gates on those maps.我在一个解决方案中使用了 OData v4 API,该解决方案允许农民绘制他们的农场和围场的地图,并且他们可以在这些地图上放置大门。

In your model, use System.Data.Entity.Spatial.DbGeography as the data type for your fields that you want to be Geography in SQL在您的模型中,使用System.Data.Entity.Spatial.DbGeography作为您希望在 SQL 中成为Geography 的字段的数据类型

In our solution the Paddocks are stored in DbGeography fields as POLYGON and MULTIPOLYGON , gates are stored in DbGeography fields as POINT .在我们的解决方案在围场存储在DbGeography领域的多边形MULTIPOLYGON,门都存储在DbGeography领域POINT。 We can query for all the paddocks in a bounding box, calculate areas and distances... pretty much all Geospatial queries our clients can throw at us...我们可以查询边界框中的所有围场,计算面积和距离......几乎所有我们的客户可以向我们提出的地理空间查询......

Notable Current Packages (However previous versions of the same packages have been running for the last year):值得注意的当前包(但是相同包的先前版本已在去年运行):

  • Entity Framework 6.4.0实体框架 6.4.0
  • Microsoft.AspNet.OData 7.3.0 Microsoft.AspNet.OData 7.3.0
  • Microsoft.AspNet.WebApi 5.2.7微软.AspNet.WebApi 5.2.7
  • Microsoft.Spatial 7.6.2微软空间 7.6.2
  • Microsoft.SqlServer.Types 14.0.1016.290 Microsoft.SqlServer.Types 14.0.1016.290
  • Newtonsoft.Json 12.0.1 Newtonsoft.Json 12.0.1

If you need to interface with GeoJSON sources, either for imports or exports, I use these packages as well, but you should be able to write a contained application without them:如果您需要与 GeoJSON 源进行交互,无论是导入还是导出,我也使用这些包,但您应该能够在没有它们的情况下编写包含的应用程序:

  • GeoJSON.Net 1.1.72 GeoJSON.Net 1.1.72
  • GeoJSON.Net.Contrib.EntityFramework 0.1.3 GeoJSON.Net.Contrib.EntityFramework 0.1.3
  • GeoJSON.Net.Contrib.MsSqlSpatial 0.3.2 GeoJSON.Net.Contrib.MsSqlSpatial 0.3.2
  • GeoJSON.Net.Contrib.Wkb 0.1.3 GeoJSON.Net.Contrib.Wkb 0.1.3

The OData serializer has not caused any trouble with serializing or deserializing these types, a query for one of the perimeters returns this: OData 序列化程序在序列化或反序列化这些类型时没有造成任何问题,对其中一个边界的查询返回:

{
    "@odata.context": ".../$metadata#Paddocks(17518)/Perimeter",
    "Geography": {
        "CoordinateSystemId": 4326,
        "WellKnownText": "POLYGON ((145.27786016464236 -37.855119294600946, 145.27687250851116 -37.855329119608058, 145.276149480753 -37.855902375057504, 145.27588481613736 -37.856685463693672, 145.2761494445584 -37.857468560509645, 145.27687247231654 -37.85804183231879, 145.27786016464236 -37.858251665505662, 145.27884785696818 -37.85804183231879, 145.27957088472633 -37.857468560509659, 145.27983551314736 -37.856685463693672, 145.27957084853173 -37.855902375057504, 145.27884782077356 -37.855329119608058, 145.27786016464236 -37.855119294600946))"
    }
}

If you are having trouble using Geography data types in the client side, you'll find its just syntax, and as such can be overcome but you'll need to post more specific issues that you are experiencing, you may find more tooling and generic support if you use GeoJSON on the client side, mapping components like leaflet js use GeoJSON natively so if you are starting from scratch on a mapping solution you may find it easier to go straight for GeoJSON integration.如果您在客户端使用 Geography 数据类型时遇到问题,您会发现它只是语法,因此可以克服,但您需要发布您遇到的更具体的问题,您可能会发现更多的工具和通用如果您在客户端使用 GeoJSON,那么像Leaflet js这样的映射组件本身就使用GeoJSON,所以如果您从头开始使用映射解决方案,您可能会发现直接进行 GeoJSON 集成更容易。

In my other question I have outlined various workarounds which do not work在我的另一个问题中,我概述了各种不起作用的解决方法

As you didn't include any links back to your previous questions, I am not sure what your previous related issues are, but I hope this gives you the confidence to persist with your solution.由于您没有包含任何指向您之前问题的链接,我不确定您之前的相关问题是什么,但我希望这能让您有信心坚持解决方案。


UPDATE更新

Instead of following the advice regarding SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));而不是遵循有关SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));

I manually copy the x86 version of the types dlls into the bin folder during deployment (because the server is running IIS 32-bit. Use the x64 versions if your server runs in 64-bit mode)我在部署期间手动将类型 dll 的 x86 版本复制到 bin 文件夹中(因为服务器运行的是 IIS 32 位。如果您的服务器在 64 位模式下运行,请使用 x64 版本)

I also have added this binding redirect in web.config:我还在 web.config 中添加了这个绑定重定向:

<assemblyBinding>
    <dependentAssembly>
        <assemblyIdentity name="Microsoft.SqlServer.Types" 
                          publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="10.0.0.0" newVersion="14.0.0.0" />
    </dependentAssembly>
</assemblyBinding>

There's nothing special in the connection string or anything else really.连接字符串或其他任何东西都没有什么特别之处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将SQL Server 2012地理数据类型与ASP.Net一起使用-DataReader.GetFieldType(x)返回null - Using SQL Server 2012 Geography Data Type with ASP.Net - DataReader.GetFieldType(x) returned null 将asp.net标识与地理授权一起使用 - Use asp.net identity with geography authorize 如何在 ASP.NET 应用程序中使用 SQL 服务器 CE - How to use SQL Server CE in an ASP.NET application Asp.Net与SQL Server和Asp.net Linq应用程序 - Asp.Net With SQL Server And Asp.net Linq Application ASP.NET应用程序池和SQL Server数据连接 - Asp.net application pool and sql server data connection 在SQL Server中为图像数据类型在ASP.NET中重置值 - Reset value in ASP.NET for Image data type in SQL Server 在ASP.NET中显示SQL Server图像数据类型 - Display SQL Server image data type in ASP.NET asp.net 4.8 web 应用程序中的应用程序洞察配置 - Application insights configuration in asp.net 4.8 web application 无法使用实体框架和 SQL 服务器数据库访问 ASP.NET MVC web 应用程序中的数据 - Unable to access data in an ASP.NET MVC web application using Entity Framework and SQL Server database 尝试使用asp.net Web应用程序将数据插入SQL Server数据库,出现错误 - Trying to insert data into SQL Server database using asp.net web application, getting an error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM