【问题标题】:The type or namespace DbContext could not be found (EF installed)找不到类型或命名空间 DbContext(已安装 EF)
【发布时间】:2017-02-21 04:43:09
【问题描述】:

我使用 MVC 应用程序制作简单的 EntityFramework。我的解决方案有 3 个项目

  • GE.BLL
  • GE.Entities
  • GE.Web

一切看起来都很棒,直到我决定将 GE.BLL 重命名为 GE.Core

所以我删除了整个项目并从头开始将所有类和引用添加到 GE.Core。现在我的这个项目的 EntityFramework 已经安装并且 System.Data.Entity 也被引用但不编译

“找不到类型或命名空间 DbContext”

我的 app.config 是

    <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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="mssqllocaldb" />
  </parameters>
</defaultConnectionFactory>
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>

packages.config 是

<packages>
 <package id="EntityFramework" version="6.1.3" targetFramework="net451" />
</packages>

我正在使用框架 4.5.1

【问题讨论】:

    标签: entity-framework asp.net-mvc-4 dbcontext csproj


    【解决方案1】:

    所以我卸载了EntityFramework并重新安装了它!

    【讨论】:

    • 是的! (我只能在 1 天后接受它作为答案)
    【解决方案2】:

    这发生在我使用 Microsoft.EntityFrameworkCore 时。问题似乎是,当我最初创建项目时,我错误地将其放入 .NET Core Web 项目中。随后,我将其在 Web 项目之外的文件夹层次结构中上移了一个级别。那是我开始看到这个错误的时候。卸载并重新安装 NuGet 包似乎不起作用,Visual Studio 建议的修复是在 Program Files 下的“nugetfallbackfolder”目录中引用 dll。

    长话短说,我最终创建了一个全新的项目,然后一切正常(无论如何,在引用了必要的 Microsoft.EntityFrameworkCore NuGet 包之后。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-10
      • 2020-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-25
      • 2017-07-12
      • 2011-05-13
      相关资源
      最近更新 更多