1
I am splitting my application in layers, I installed the 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 installing and reinstalling the EF in the layers, however, the error continues.
Class Context
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; }
}
}
Code from the Repository layer app.config
<?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>
package of the Repository layer
<?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 app 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>
package of layer Application
<?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>
Which ones Packages you installed in the layers? Can you edit your question?
– Leonel Sanches da Silva
Jéferson, I didn’t understand very well the Magic links and the problem of the provider I’m having difficulties, what is the relationship?
– Kelly Soares
You may have installed Entity but forgot to reference them in the other layers, add the reference to the file Entityframework.SqlServer.dll in all layers of your project... One thing I didn’t understand is that there is no connection string in any of yours. config.
– Rafael Ferreira
Rafael is because I am running this string in the constructor of my context class. I will post my full code.
– Kelly Soares