Tho*_*der 90 asp.net-mvc entity-framework azure
我正在尝试在ASP.NET MVC 4中创建一个webapi.webapi使用了Entity Framework 5 Spatial类型,我编写了一个非常简单的代码.
public List<Area> GetAllAreas()
{
List<Area> aList = db.Areas.ToList();
return aList;
}
Run Code Online (Sandbox Code Playgroud)
区域包含DbGeometry.
当我运行这个本地它工作,但当我发布到azure它给我这个错误:
空间类型和函数不适用于此提供程序,因为无法找到程序集"Microsoft.SqlServer.Types"版本10或更高版本.
有谁知道如何解决这个问题?:)
谢谢!
Tho*_*der 122
我找到了解决方案!只需安装nuget包Microsoft.SqlServer.Types即可
PM>安装包Microsoft.SqlServer.Types
Chr*_*ris 103
当可以使用程序集的版本11(SQL Server 2012)时,上面的答案可以正常工作.
我遇到了问题,因为我的解决方案对同一程序集的版本13(SQL Server 2016)有其他依赖性.在这种情况下,请注意实体框架(至少v6.1.3)在其SqlTypesAssemblyLoader(此异常的源)中进行硬编码,以仅查找程序集的版本10和11.
为了解决这个问题,我发现你可以告诉Entity Framework你想要使用哪个程序集:
SqlProviderServices.SqlServerTypesAssemblyName = typeof(SqlGeography).Assembly.FullName;
Run Code Online (Sandbox Code Playgroud)
R2D*_*2D2 62
出于某种原因,我错过了一个绑定重定向,它为我解决了这个问题.
添加以下修复了我的问题
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
Tar*_*lah 24
有两种方法可以解决这个问题:
第二种方法是使用NuGet包管理器并安装
安装包Microsoft.SqlServer.Types
然后按照下面的插件说明进行操作
若要将使用空间数据类型的应用程序部署到未安装"SQL Server的CLR类型"的计算机,还需要部署本机程序集SqlServerSpatial110.dll.此程序集的x86(32位)和x64(64位)版本已添加到SqlServerTypes\x86和SqlServerTypes\x64子目录下的项目中.如果未安装C++运行时,还包括本机程序集msvcr100.dll.
您需要添加代码以在运行时加载这些程序集中正确的一个(取决于当前的体系结构).
ASP.NET应用程序对于ASP.NET应用程序,将以下代码行添加到Global.asax.cs中的Application_Start方法:
Run Code Online (Sandbox Code Playgroud)SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));桌面应用程序对于桌面应用程序,在执行任何空间操作之前,添加以下代码行以运行:
Run Code Online (Sandbox Code Playgroud)SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
Inu*_*ère 13
我也遇到过这个问题,但是已经安装了Microsoft.SqlServer.Types nuget包.
为我解决问题的是解决方案>参考> System.Data.Entity>属性>复制本地,并将其设置为True.
注意: Microsoft.SqlServer.Types的Copy Local已设置为true,即使问题出在System.Data.Entity上,错误消息仍然是Microsoft.SqlServer.Types.
解决方案来自Windows Azure论坛.
对我来说,解决方案是将以下代码行添加到Global.asax.cs中Application_Start():
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
Run Code Online (Sandbox Code Playgroud)
兄弟们,祝你好运。
小智 5
请在Web.config文件中添加“ dependentAssembly”
<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>
Run Code Online (Sandbox Code Playgroud)
这对我有用
| 归档时间: |
|
| 查看次数: |
49183 次 |
| 最近记录: |