2014-10-16 83 views
0

我想用Code First先私人部署SQL CE WPF与实体框架6。SQLCE 4私人部署实体框架6

在开发计算机数据库,应用程序数据文件夹中生成细和所有测试PC上我得到一个异常(没有DB),但是工作得很好:

"The ADO.NET provide with invariant name 'System.Data.SQlServerCe.40' is either not registered in the machine or application config file' 

我试图执行关于这个问题的所有现有的文献,但仍然有问题。我已经使用Deployed Folder检查了Bin文件夹,它也是一样的,所有库(x86和amd64)都存在,并且Project Platform目标是x86。

  1. No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0'
  2. http://erikej.blogspot.dk/2013/11/entity-framework-6-sql-server-compact-4_25.html
  3. Entity Framewok Code First "ADO.NET provider not found" with local SQL Server CE DLL's

贝娄是我的App.config

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    </configSections> 

    <entityFramework> 
    <contexts> 
     <context type="MyProject.DAL.GreatContext, MyProject"> 
     <databaseInitializer type="MyProject.Module.Database.Dal.GreatDbInitializer, MyProject" /> 
     </context> 
    </contexts> 
    <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> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="System.Data.SqlServerCe.4.0" /> 
     </parameters> 
    </defaultConnectionFactory> 
    </entityFramework> 

    <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.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/> 
    </DbProviderFactories> 
    </system.data> 


</configuration> 

我也开始加入了波纹管代码,但仍问题仍然存在:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 

有什么想法?

+0

是包含在你的项目什么System.Data.SqlServerCe.dll的程序集版本? – ErikEJ 2014-10-16 18:29:21

回答

2

假设你使用ado.net提供商的4,0,0,1版本,你需要使用该程序集重定向:

<runtime> 
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
    <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral"/> 
    <bindingRedirect oldVersion="4.0.0.0-4.0.0.1" newVersion="4.0.0.1"/> 
    </dependentAssembly> 
</assemblyBinding> 

重定向Entityframework.dll将无法正常工作。

以及适当的解决办法是使用我的EntityFramework.SqlServerCompact.PrivateDeployment NuGet包

+0

嗨,Erik,我也试过这个代码,并且在开发电脑上得到了“定位的程序集的清单定义不符合assebmly引用”的异常。 – Jim 2014-10-16 18:42:58

+0

您是否在使用程序集版本4,0,0,1?这里的一些技巧http://stackoverflow.com/questions/215026/the-located-assemblys-manifest-definition-does-not-match-the-assembly-reference – ErikEJ 2014-10-16 18:52:54

+0

System.Data.SqlServerCe:版本4.0.0.0,请指教如果我应该升级?我已经通过Nuget添加了它们 – Jim 2014-10-16 19:00:29