Should I include Entity Framework in my class library or directly into application?

c# entity-framework entity-framework-6

Question

You might have encountered this type of question before but in my case, it's a bit different scenario and I cannot find a feasible answer. (It might exist already, however I was not able to find one).

I'm working on a business application which has the entire functionality split into multiple class libraries. I'm using Entity Framework and I'm not sure which is the right place to include it? In my case, I've these libraries:

  • Project.Library.Core
  • Project.Library.Models (Contains the entity data model and entities).
  • Project.Library.Auth (Contains authentication related and user management classes).
  • and similar classes who frequently use the entities and the db context.

In order to make this work, I've to install Entity Framework in every library separately. Eventually they will be included in a number of ASP.NET MVC Web Applications. I'd have installed Entity Framework directly into the web apps but this application will have mobile apps in the future along with a possible windows store app. In that case, I can simply set up a ASP.NET Web API and use the existing class libraries to generate the required data. This is the only factor holding me back from incorporating Entity Framework directly into the web apps.

So what's your opinion on this? Include Entity Framework in every library separately (required to function properly) or simply include in the web app and later follow the same approach for the Web API?

Thank you.

1
3
6/17/2016 11:30:05 PM

Accepted Answer

You only need to "install" EntityFramework into one place: Project.Library.Models. Assuming standard code-first objects as your DTOs, you won't need a direct reference anywhere else as long as you wrap the context object with a Data Access Layer.

Adding a reference to that assembly will cause the requisite DLLs to be included with your apps, web sites, etc. Note that if you are using EntityFramework.SqlServer, the transient dependency won't be detected by Visual Studio so you need to do something like:

class Include
{
    private Include() { }
    private SqlProviderServices IncludeSql;
}

Somewhere in the models project so that DLL is copied over also.

2
6/17/2016 11:58:44 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow