Entity Framework 加载时抛出异常

Entity Framework throwing exception while loading

我正在尝试在 Entity Framework 中编写我的第一个应用程序。

program.cs(我的 main() 所在的位置)我有行 ProdContext ctx = new ProdContext();prodContext.cs 是:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Entity;
using System.Text;

namespace Entity_Framework
{
    class ProdContext : DbContext
    {
        public DbSet<Category> Categories { get; set; }
        public DbSet<Product> Products { get; set; }
    }
}

在尝试 运行 main 时,我在上面一行遇到异常:


FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

我使用 C# 和 EF 全新安装了 Visual Studio(我使用 install-package entityframework -version 6.1.3.0 安装了它)。为什么我会收到该异常?

我建议您在尝试安装 .NET 库的同时使用 .NET Core 应用程序。 EF 6 是“.NET”特定的库。对于您的项目的 .NET Core 应用程序类型,如果安装 .NET EF 版本,您将遇到这样的崩溃(或类似的):

对于 .NET Core 应用程序,您应该安装 Core 版本。 https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/

确保您的参考文献中没有此(或类似)错误: