实体框架代码优先迁移在错误的提供程序上失败(3.5而不是4.0) [英] Entity Framework Code First Migrations failing on Wrong Provider (3.5 instead of 4.0)

查看:76
本文介绍了实体框架代码优先迁移在错误的提供程序上失败(3.5而不是4.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Entity Framework 6.0.2 for SQL Server Compact(代码优先)向项目添加迁移(第一次)。应用程序与数据库通信没有问题。迁移失败并显示错误消息:

I am trying to add a migration (for the first time) to a project using Entity Framework 6.0.2 for SQL Server Compact (code first). The application is having no problems communicating with the database. The migration is failing with the error message:


System.InvalidOperationException:

找不到ADO的实体框架提供程序.NET提供者,其不变名称为 System.Data.SqlServerCe.3.5。确保提供商已在应用程序配置文件的 entityFramework部分中注册。

System.InvalidOperationException:
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.3.5'. Make sure the provider is registered in the 'entityFramework' section of the application config file.

该项目从未引用过 SqlServerCe.3.5 ,我不能使用Visual Studio查找一个替换命令

The project has never had any reference to SqlServerCe.3.5 and I cannot find one with Visual Studio find & replace command

app.config 文件具有:

<configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
      </dependentAssembly>
  </assemblyBinding>
</runtime>
<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
    <parameters>
      <parameter value="System.Data.SqlServerCe.4.0" />
    </parameters>
  </defaultConnectionFactory>
</entityFramework>
<appSettings>
<system.data>
  <DbProviderFactories>
    <remove invariant="System.Data.SqlServerCe.4.0" />
    <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
  </DbProviderFactories>
</system.data>

有人知道我如何强制迁移使用 SqlServerCe.4.0 code>(+/-删除对3.5的引用)?谢谢。

Does anyone know how I can force migrations to use SqlServerCe.4.0 (+/- remove the reference to 3.5)? Thank you.

编辑


非常感谢Sql Server Compact先生(ErikEJ)的建议。

Edit

Many Thanks to Mr Sql Server Compact (ErikEJ) for his suggestions.

不幸的是,删除绑定重定向节点只会导致:

unfortunately, removing the binding redirect node just results in:


System.Data.Entity.Core。 ProviderIncompatibleException:
从数据库获取提供者信息时发生错误。这可能是由于Entity Framework使用了错误的连接字符串引起的。检查内部异常以获取详细信息,并确保连接字符串正确。 ---> System.Data.Entity.Core.ProviderIncompatibleException:提供程序未返回ProviderManifestToken字符串。 ---> System.ArgumentException:给定的连接不是'SqlCeConnection'类型。

System.Data.Entity.Core.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. ---> System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.ArgumentException: The connection given is not of type 'SqlCeConnection'.

您绝对正确-该项目是使用私有部署。 System.Data.SqlServerCe和System.Data.SqlServerCe.Entity的引用程序集版本均为4.0.0.1

You are absolutely correct - this project is using private deployment. Referenced assembly versions for System.Data.SqlServerCe and System.Data.SqlServerCe.Entity are both to 4.0.0.1

我需要按照erik的建议删除绑定重定向节点,并将提供程序添加到应用程序配置的EntityFramework节点(该应用程序使用提供程序服务的基于代码的配置,因此这些不是

I needed to remove the binding redirect node, as suggested by erik, AND add the provider to the EntityFramework node of the app config (the application uses code-based configuration of the provider services, so these were not included) as below

<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>


推荐答案

删除绑定重定向。似乎您正在尝试使用私人部署,但您使用的是正确的System.data.SqlServerCe.dll(检查程序集版本)。如果它是4.0.0.0而不是4.0.0.1,则更改为DbProviderfactories设置以指向正确的程序集版本

Remove the binding redirect. It looks like you are trying to use private deployement, but are you using the correct System.data.SqlServerCe.dll (check the Assembly version). if it is 4.0.0.0 and not 4.0.0.1, then change to DbProviderfactories setting to point to the correct assembly version

这篇关于实体框架代码优先迁移在错误的提供程序上失败(3.5而不是4.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆