ASP.NET MVC 4实体框架6 SQL Compact Edition 4.0部署无需安装

前端之家收集整理的这篇文章主要介绍了ASP.NET MVC 4实体框架6 SQL Compact Edition 4.0部署无需安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图部署一个使用Entity Framework 6(Code First)和sql Compact 4.0的基本MVC 4应用程序
在安装了iis的 Windows 7的干净安装上(未安装mvc 4和sql compact 4.0).

我在db项目上安装了以下nuget包:

> EntityFramework(版本6.0.0-alpha2)
> EntityFramework.sqlServerCompact(Version 6.0.0-alpha2)
> Microsoft.AspNet.Providers(版本1.2)
> Microsoft.AspNet.Providers.Core(版本1.2)
> Microsoft.sqlServer.Compact(版本4.0.8876.1)

在web.config中,我得到了以下配置:

<connectionStrings>
  <add name="[Name]" connectionString="Data Source=|DataDirectory|[FileName].sdf" providerName="System.Data.sqlServerCe.4.0" />
</connectionStrings>  

......................

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.sqlConnectionFactory,EntityFramework">
     <parameters>
        <parameter value="System.Data.sqlServerCe.4.0" />
     </parameters>
  </defaultConnectionFactory>
  <providers>
      <provider invariantName="System.Data.sqlServerCe.4.0" type="System.Data.Entity.sqlServerCompact.sqlCeProviderServices,EntityFramework.sqlServerCompact,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" />
  </providers>
</entityFramework>

Bin文件夹(sql ce文件位于amd64和x86文件夹中:

> [amd64]
> [x86]
> Antlr3.Runtime.dll
> DotNetOpenAuth.AspNet.dll
> DotNetOpenAuth.Core.dll
> DotNetOpenAuth.OAuth.Consumer.dll
> DotNetOpenAuth.OAuth.dll
> DotNetOpenAuth.OpenId.dll
> DotNetOpenAuth.OpenId.RelyingParty.dll
> EntityFramework.dll
> EntityFramework.sqlServer.dll
> EntityFramework.sqlServer.xml
> EntityFramework.sqlServerCompact.dll
> EntityFramework.sqlServerCompact.xml
> EntityFramework.xml
> Microsoft.Web.Infrastructure.dll
> Microsoft.Web.WebPages.OAuth.dll
> Newtonsoft.Json.dll
> ShipMedProto.DB.dll
> ShipMedProto.DB.pdb
> ShipMedProto.Web.dll
> ShipMedProto.Web.pdb
> System.ComponentModel.DataAnnotations.dll
> System.Data.DataSetExtensions.dll
> System.Data.sqlServerCe.dll
> System.Data.sqlServerCe.Entity.dll
> System.Net.Http.Formatting.dll
> System.Web.Helpers.dll
> System.Web.Http.dll
> System.Web.Http.WebHost.dll
> System.Web.Mvc.dll
> System.Web.Optimization.dll
> System.Web.Providers.dll
> System.Web.Razor.dll
> System.Web.WebPages.Deployment.dll
> System.Web.WebPages.dll
> System.Web.WebPages.Razor.dll
> WebActivatorEx.dll
> WebGrease.dll
> WebMatrix.Data.dll
> WebMatrix.WebData.dll

当我部署到干净的机器时,我收到以下错误消息:

无法找到请求的.Net Framework数据提供程序.它可能没有安装.

在我的开发机器上它工作正常. (我安装了sql ce)

我有什么问题吗?

解决方法

我认为您真正想要做的是管理NuGet包,以便为EntityFramework添加sqlServerCompact支持.只需右键单击您的引用和Manager NuGet包.然后在对话框中搜索sqlServerCompact.你应该看到这个:

添加它应该添加上面答案中的等效字符串.我最终在web.config(或app.config,如果你正在做一个应用程序)中这样做了

<entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.sqlCeConnectionFactory,EntityFramework">
          <parameters>
            <parameter value="System.Data.sqlServerCe.4.0" />
          </parameters>
        </defaultConnectionFactory>
        <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>   
</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,PublicKeyToken=89845dcd8080cc91" />
        </DbProviderFactories>   
</system.data>

对不起,我迟到了一年,但希望这有助于其他人.

原文链接:https://www.f2er.com/aspnet/247292.html

猜你在找的asp.Net相关文章