DynaWeb
DynaWeb

Reputation: 605

EntityFramework.SqlServer missing from nuget?

Context

Details

I've been working through Entity Framework 6's docs here as well as some other resources. Everything I've found in regards to EF6 is quite dated. Case in point it "says" it'll add things to the config file when you install via nuget manager but doesn't...

The entityFramework section was automatically added to the configuration file of your project when you installed the EntityFramework NuGet package.

Frustrating but I can work around that, not my first app.config.

However what confuses me further down in the Entity Framework docs is the provider registration. Nuget was supposed to install a reference to EntityFramework.SqlServer, but it never did. I could also not install it via nuget package manager. I managed to find it in nuget.org but is unlisted and hasn't been updated since 2015

<providers>
    <provider invariantName="System.Data.SqlClient" 
              type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>

Question

Do I still even need EntityFramework.SqlServer? I can easily add it in if I have too but is this the correct approach? Do people still use this old .dll out in the real world/prod?

I am curious to see how one with more experience with ET 6 would configure a fresh project.

UPDATE - DEC-9-2019

So digging into a little more, this behaviour doesn't work if you're installing Nuget packages with PackageReference rather than Package.config. You can change it by navigating to Tools --> Options--> Nuget Package Manager --> General --> Default package management format

Upvotes: 2

Views: 8948

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89291

Just adding the EntityFramework NuGet package to your empty Windows Forms project should add the following references in your .csproj:

  <ItemGroup>
    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>..\packages\EntityFramework.6.4.0\lib\net45\EntityFramework.dll</HintPath>
    </Reference>
    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>..\packages\EntityFramework.6.4.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.ComponentModel.DataAnnotations" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Deployment" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
  </ItemGroup> 

And the following in your 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>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
    </startup>
    <entityFramework>
        <providers>
            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
        </providers>
    </entityFramework>
</configuration>

Upvotes: 3

Related Questions