I want to encapsulate Entity Framework in one project. This project will do DB access alone. When updating, I want to map a domain model to EF. The purpose is that other layers of the solution should have no knowledge of infrastructure.
My problem is that I need to reference EF in my "caller" project to make it work.
Is there a way to avoid this?
Solution - ConsoleProject - EntityFrameworkProject (EF from Nuget)
With EF6 and code based configurations, this is now possible.
[DbConfigurationType(typeof(MyDbContextConfiguration))]
internal class MyDbContext : DbContext
{
public DbSet<MyModel> MyModels { get; set; }
}
internal class MyDbContextConfiguration : DbConfiguration
{
public MyDbContextConfiguration()
{
SetProviderServices("System.Data.SqlClient", SqlProviderServices.Instance);
}
}
If you configure your database in Project A as above, then only Project A needs to reference EntityFramework, and any project that references it, like Project B will not try to find the provider in its own assembly.
Expose your repositories in Project A, and add a <connectionStrings> configuration in Project B, and it should work flawlessly.
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