Apologies if this has already been answered, but after 2 hours of research I am yet to find a definitive answer to this issue. Hopefully asking will yield results.
I'm "somewhat better than beginner" with MVC and EF, but I do understand overall application architecture. You see, for even greater Separation of Concerns and future planned changes, I'd like to decouple my MVC project from Entity Framework. Here's what I have so far:
I've already created my Repository pattern (in the DataAccess project), and tested it using a separate UnitTest project. It all works.
Problem is, the consumer (the UnitTest project, in this case) still needs a nuget reference to Entity Framework (same with the MVC Web project). When I remove the EF reference from my Test project (and instead hard-code my connection string when passing it into my DataAccess project), I get this error:
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.
How can I design this so I can completely remove the Entity Framework reference from the Repository consumer (UnitTest or MVC Web projects)? I want to do everything via my Repository, without the MVC project knowing anything about my ORM technology.
This is a bit misguided. First, the reason a reference to Entity Framework is required is because you're leaking code from that library into your MVC project. The only way to avoid a reference is to 100% segregate the code. Which is potentially possible, but not easy by any stretch. However, that's not important anyways. Having a reference to Entity Framework is meaningless. The important part of N-tier design is segregating distinct functionality, not necessarily references. If your DAL depends on EF and your MVC project depends on your DAL, then you have an inherent dependency on EF anyways.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With