EF 6对System.Data.Entity的依赖关系

本文关键字:依赖 关系 Entity Data System EF | 更新日期: 2023-09-27 18:28:11

对于EF6,我的理解是所有与EF相关的类都已移动到EntityFramework.dll中

namespace ConsoleApplication1
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
    public partial class MyDataModel : DbContext
    {
        public MyDataModel ()
            : base("name=MyDataModel ")
        {
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

此DbContext类是在System.Data.Entity中定义的,但项目本身在references节中没有对System.Data.Eentity.dll的任何引用。两个问题

  1. 这是否意味着EF仍然依赖于System.Data.Entity
  2. 为什么在这种情况下没有引用System.Data.Entity.dll

EF 6对System.Data.Entity的依赖关系

System.Data.Entity是EF6的一部分。请参阅此处

您将不需要对System.Data.Entity的引用(它包含在EntityFramework.dll中)。

但是,请确保正确安装了EF 6.x。http://msdn.microsoft.com/en-us/data/ee712906.aspx

  • 输入:安装程序包EntityFramework
  • 在点击输入键之前,如果您的解决方案包含多个项目,请确保您的项目选择了Package Manager控制台顶部的Default project下拉列表

一旦安装,您将注意到两个新的参考:

  • EntityFramework.dll
  • EntityFramework.SqlServer.dll

另外,包文件将包含

<packages>
  <package id="EntityFramework" version="6.1.1" targetFramework="net45" />
</packages>

你的app.config文件将包含

<configuration>
  <configSections>
    <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.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>