[英]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):值得注意的当前包(但是相同包的先前版本已在去年运行):
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 源进行交互,无论是导入还是导出,我也使用这些包,但您应该能够在没有它们的情况下编写包含的应用程序:
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.由于您没有包含任何指向您之前问题的链接,我不确定您之前的相关问题是什么,但我希望这能让您有信心坚持解决方案。
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.