2

Context

  • Creating an Entity Framework data layer (experience with Hibernate)
  • Connecting to SQL Server Express
  • Client is a simple desktop application
  • I can't use Entity Framework CORE

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

1
  • 2
    EntityFramework.SqlServer is part of Entity Framework Core - not the "base" Entity Framework (v6.x) that's running on the full .NET framework Commented Dec 6, 2019 at 5:03

1 Answer 1

3

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>
Sign up to request clarification or add additional context in comments.

2 Comments

So for clarification, this behaviour only works with the Package.config format within Tools --> Options--> Nuget Package Manager --> General --> Default package management format (at least for me). Prior to modifying it I had it set to PackageReference.
Marking as answered since it clarifies what 'should' happen

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.