【问题标题】:change entity framework reference in webapi在 webapi 中更改实体框架引用
【发布时间】:2014-12-03 16:20:49
【问题描述】:

我目前有一个使用 Entity Framework6 程序集引用的 .Net WebAPI2 项目。这是我的“生产”环境。我创建了一个并行的“测试”环境,其中包含一个新的测试 sql 数据库(生产数据库的副本)以及一个 WebAPITest 和 EFTest 作为相关产品 VS2013 项目的副本。我能够在新 EFTest 的 app.config 中将数据库更改为 DBTest,这似乎工作正常。我将 WebAPITest 中的引用更改为指向新的 EFTest 程序集,并且似乎已正确连接。问题是,当我在 VS2013 中实际运行 WebAPITest 项目并调用 WebAPITest 控制器时,它仍然触及原始的 EF 和 API。我还在 WebAPITest 的 Web.config 中注释掉了,但它仍然指向运行时的旧连接。

在 WebAPITest 中创建新控制器成功并且引用 EFTest 似乎都可以正常工作,没有构建错误,但是从 VS 运行以尝试新控制器返回并且新控制器不存在并且任何先前存在的控制器仍然命中旧控制器的错误显然是 EF。

我尝试清除浏览器缓存但没有成功。 我可以更新哪些其他参考位置来解决此问题?

来自 WebAPITest 的 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" />
  </configSections>
  <connectionStrings>
    <add name="RecTaxEntities" connectionString="metadata=res://*/RecTaxEFModel1.csdl|res://*/RecTaxEFModel1.ssdl|res://*/RecTaxEFModel1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=myserver;initial catalog=DB;user id=USER;password=PWD;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

来自 WebAPITest 的 Web.Config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301879
  -->
<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" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <!-- <add name="RecTaxEntities" connectionString="metadata=res://*/RecTaxEFModel1.csdl|res://*/RecTaxEFModel1.ssdl|res://*/RecTaxEFModel1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=myserver;initial catalog=DB;user id=USER;password=PWD;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />-->
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

【问题讨论】:

  • 您可以在这里发布web.config 和任何其他.configs 吗?
  • 为什么你不用大写字母来开始你的问题标题?为什么你的问题标题中没有问号?问题标题需要形成良好的格式,以便问题列表看起来像实际问题的列表。

标签: c# asp.net-web-api runtime-error entity-framework-6


【解决方案1】:

问题解决了。它最终成为我试图从新测试环境中调用的 WebAPI 控制器名称的 typeo。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    • 2011-07-24
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多