No Entity Framework provider found for ADO.NET provider [closed]

1

I am dividing my application in layers, I installed EF in the application layers and repository, in my view everything is correct, but I am having the following error:

  

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient.

I researched some similar questions here on the site, followed the same steps by installing and reinstalling the EF in the layers, but the error continues.

Context Class

using MvcNorthwindExemplo.Dominio;
using System.Data.Entity;

namespace MvcNorthwindExemplo.Repositorio
{
    public class DBNorthwindContext : DbContext
    {
        public DBNorthwindContext()
            : base(@"Data Source=(local); Initial Catalog=NorthwindExemplo; Integrated Security=true")
        {            
        }

        public DbSet<Regiao> Regioes { get; set; }
    }
}

Repository layer app.config code

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

Repository layer package

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.1.3" targetFramework="net451" />
  <package id="Glimpse" version="1.8.6" targetFramework="net451" />
  <package id="Glimpse.Ado" version="1.7.3" targetFramework="net451" />
  <package id="Glimpse.AspNet" version="1.9.2" targetFramework="net451" />
  <package id="Glimpse.EF6" version="1.6.5" targetFramework="net451" />
  <package id="Glimpse.Mvc5" version="1.5.3" targetFramework="net451" />
</packages>

Application Class

using MvcNorthwindExemplo.Dominio;
using MvcNorthwindExemplo.Repositorio;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

namespace MvcNorthwindExemplo.Aplicacao
{
    public class RegiaoAplicacao
    {
        public DBNorthwindContext db { get; set; }

        public RegiaoAplicacao()
        {
            db = new DBNorthwindContext();
        }

        public void AddRegiao(Regiao regiao)
        {
            db.Regioes.Add(regiao);
            db.SaveChanges();
        }

        public void UpdateRegiao(Regiao regiao)
        {
            db.Entry(regiao).State = EntityState.Modified;
            db.SaveChanges();
        }

        public void Excluir(long? id)
        {
            var regiao = db.Regioes.Where(r => r.RegiaoID == id).FirstOrDefault();
            if (regiao != null)
            {
                db.Regioes.Remove(regiao);
                db.SaveChanges();
            }
        }

        public Regiao GetRegiaoFind(long id)
        {
            return GetRegiaoAll().Where(r => r.RegiaoID == id).FirstOrDefault();
        }

        public IEnumerable<Regiao> GetRegiaoAll()
        {
            return db.Regioes.ToList();
        }        
    }
}

Application Layer.config code

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

Application layer package

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.1.3" targetFramework="net451" />
  <package id="Glimpse" version="1.8.6" targetFramework="net451" />
  <package id="Glimpse.Ado" version="1.7.3" targetFramework="net451" />
  <package id="Glimpse.AspNet" version="1.9.2" targetFramework="net451" />
  <package id="Glimpse.EF6" version="1.6.5" targetFramework="net451" />
  <package id="Glimpse.Mvc5" version="1.5.3" targetFramework="net451" />
</packages>
    
asked by anonymous 22.09.2015 / 18:53

2 answers

1

Make sure your layers refer to the default .NET library System.Data . This is where the namespace is System .Data.SqlClient .

    
22.09.2015 / 19:32
1

I was able to solve the problem by creating a class to remove EF dependencies:

public class MyConfiguration : DbConfiguration
{
    public MyConfiguration()
    {
        SetProviderServices(
            System.Data.Entity.SqlServer.SqlProviderServices.ProviderInvariantName,
            System.Data.Entity.SqlServer.SqlProviderServices.Instance);
    }
}
    
22.09.2015 / 20:01