Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to SQL Server with EF6

Up to EF5, in order to connect to SQL Server 2012, all I needed to to is specify a connection string that looks something like this:

Data Source=.\SqlExpress;Initial Catalog=MyDatabase;Integrated security=True;MultipleActiveResultSets=True

This method is not working with EF6, giving exception

No Entity Framework provider found for 'System.Data.Odbc' ADO.NET provider. Make sure the provider is registered in the 'entityFramework' section of the application config file

I am not using app.config file at all, I am passing above connection string to MyContext constructor. WHy is it trying to use Odbc provider at all, and instead not using System.Data.SqlClient?

What needs to be done to connect to SQL Server with EF6 code-first? I made sure that EntityFramework.dll and EntityFramework.SqlServer.dll are both available in Application folder. I have even added EF6 nuget package v6.0.0.1 in WPF project, although it does not use EF library directly, and making sure that automatically created App.Config file (by nuget) is copied to Application (Debug) folder - still no success.

I have also tried to setprovider manually in code:

public class OeeCoachConfiguration : DbConfiguration
{
    public OeeCoachConfiguration()
    {
        SetProviderServices("System.Data.SqlClient",
            System.Data.Entity.SqlServer.SqlProviderServices.Instance);
    }
}

Still no success. My Project structure is as follows (simplified):

WPF project - does not have reference to EF (also tried adding EF reference)

ViewModel class library - does not have reference to EF

Model class library - has reference to EF library (both dlls)

Data class library - has reference to UI library (both dlls).

I am using CodeFirst approach, and this setup works without any problem with EF5. Any help is greatly appreciated.

like image 730
Goran Avatar asked Apr 06 '13 23:04

Goran


People also ask

Is EF6 still supported?

Although Entity Framework 6. x is still supported, it is no longer being developed and will only receive fixes for security issues.

Should I use EF or EF6?

Keep using EF6 if the data access code is stable and not likely to evolve or need new features. Port to EF Core if the data access code is evolving or if the app needs new features only available in EF Core. Porting to EF Core is also often done for performance.


1 Answers

For me this error was resolved by removing the Glimpse.ADO package

Edit December 20, 2013 I believe the Glimpse.ADO package now supports EF6, but I have not tested it.

like image 182
taylonr Avatar answered Sep 21 '22 20:09

taylonr