0

I'm using EF 5.x DbContext generator to put my entites in a separate project. When doing this I also make my project dependent on EntityFramework. It seems to be necessary because of the DbContext generated in my project depend on Entity Framework.

Is it possible to keep my DbContext in one project and have my entities in a separate project which not depend on EF?

Erik Z
  • 4,660
  • 6
  • 47
  • 74
  • possible duplicate of [Entity Framework 5 and Visual Studio 2012 POCO Classes in Different Project](http://stackoverflow.com/questions/12375090/entity-framework-5-and-visual-studio-2012-poco-classes-in-different-project) – Gert Arnold Sep 30 '13 at 09:37
  • Not exactly, I want to keep the dbcontext in one project and my entites in another project. – Erik Z Sep 30 '13 at 11:02
  • How about this: http://stackoverflow.com/q/2464909/861716? – Gert Arnold Sep 30 '13 at 11:15

1 Answers1

0

You can achieve this by using entity code first approach.

I would create 3 projects:

1 - Model - Here you have your POCO classes.(no EF dependecy)

2 - EntityMapper - Here you will create the configuration classes for the POCO classes.(EF dependent)

3 - DataContext - Here you have your context(EF dependent). Here you specify the entities you would like to have as DbSets, and on modelbuilder, you specify the configuration classes from the second project.

If you prefer, you can map the entities within third project, eliminating the need for the second. But you will have to create a new mapping for any new context that you create.

Guardian
  • 89
  • 1
  • 12