我有一个 ASP.NET MVC5 项目 EF6。
在更新所有 nuget 包(包括 Microsoft.SqlServer.Types(版本 14.0.314.76((后,所有与 spartial 类型相关的查询都不再起作用,它告诉我将这行代码包含在 Global.asax 中的 Application_Start(( 方法中.cs
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
但它不能解决问题
Exception thrown: 'System.InvalidOperationException' in mscorlib.dll
Additional information: Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.
这是我到目前为止尝试过的
- 重新安装 nuget 包
- 在 SqlServerTypes 文件夹中设置.dll以复制 alsway、删除 bin 和 obj 文件夹并重建
若要测试它是否有效,请将此简单代码插入到主控制器中的 Index 方法中
DbGeometry test = DbGeometry.FromText("POINT(297937 574201)", 27700);
实体框架中的一个错误。对 SQL Server 类型的依赖关系设置为版本 10 或 11,而不是版本 10 或更高版本。
解决方法是在请求版本 10 时添加重定向以使用版本 14:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
实体框架错误报告:https://github.com/aspnet/EntityFramework6/issues/244