Removing Entity Framework Link from MVC Project

Sorry if this has already been answered, but after 2 hours of research I have not yet found a definitive answer to this question. I hope that the task will give results.

I am "somewhat better than a newbie" with MVC and EF, but I understand the general architecture of applications. You see, to further separate problems and future planned changes, I would like to separate my MVC project from the Entity Framework. Here is what I still have:

  • Design models (full of well-annotated POCOs, like containers, not business logic)
  • DataAccess project (refers to the project of my models and Entity Framework)
  • MVC web project (which only refers to my model project)

I already created a repository template (in the DataAccess project) and tested it with a separate UnitTest project. Everything is working.

The problem is that the consumer (UnitTest project in this case) still needs to bind the link to the Entity Framework (the same with the MVC web project). When I remove the EF link from my test project (and instead hardcode the connection string when passing to the DataAccess project), I get this error:

There is no Entity Framework infrastructure provider for the ADO.NET provider with the invariant name "System.Data.SqlClient". Make sure the provider is registered in the "entityFramework" section in the application configuration file.

, Entity Framework (- UnitTest MVC)? , MVC, - ORM.

+4
4

. -, , Entity Framework, , MVC. - 100% . , . , . Entity Framework . N- - , . DAL EF, MVC DAL, EF .

+3

, Visual Studio , . :

public DbContext() 
    :base()
{
   var a = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}
+1

NuGet ( / -), EF. csproj. , , .

<entityFramework>
    ...    
    <providers>
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
</entityFramework>

, , , EF afaik.

0

You can try to access your services through a web API that acts as a buffer for the data access layer, and transactions in view models are pushed back and forth as anonymous JSON objects. Then your interface (website) can be completely isolated from the details of the API and just act as a client for it. Angular JS / Angular (2) lends itself well to this approach, as I'm sure many other client-side technologies do.

0
source

Source: https://habr.com/ru/post/1652057/


All Articles