0
Hello, everyone.
I basically have a data access layer with EF6 and a presentation layer (Asp.Net Webapi). I am unable to make it work without the presentation layer referring to EF. Does anyone know how to solve this?
My solution is currently like this:
Core - sem dependências
Domain - depende da Core
DataAccess - depende da Core, Domain e EF
WebApi - depende da Core, Domain e DataAccess (e EF, mas não deveria)
There is no public class in Dataaccess that exposes any EF dependency (Dbcontext, Dbset, etc). Instead, there is a set of own facade classes (Façade).
No reference occurs this exception in the first line of code that makes access to the data:
[System.InvalidOperationException]
No Entity Framework provider found for the ADO.NET provider with invariant name
'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework'
section of the application config file.
See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
Adding the EF section on Web.config (but no reference to EF) this other exception occurs right at the Dbcontext instantiation:
[System.InvalidOperationException]
The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'
registered in the application config file for the ADO.NET provider with invariant name
'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is
used and that the assembly is available to the running application.
See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
Surely you are accessing the data layer directly without using the di (dependency Injection)
– Marco Souza
And how would I do that? Any example? The Dataaccess layer exposes no EF class.
– Eric Cordeiro
http://desenvolvedor.ninja/inversao-de-controle-e-injecao-de-dependencia-no-asp-net-core/
– Marco Souza
http://desenvolvedor.ninja/dryioc-inversao-de-controle-e-injecao-de-dependencia-no-net/
– Marco Souza
I am not developing Asp.Net Core or EF Core. I am with Framework 4.7.1 and EF6.
– Eric Cordeiro
this works for any version
– Marco Souza
As far as I know, it’s not possible. The running application (whether a Web API, a WPF, a Console, or even a test project) needs to have the EF installed (even using DI), and I don’t understand why that would be a problem.
– Alisson