0

I am developing an asp.net mvc project which consist of a core library and other libraries (as modules). In core biliary I defined main entities like UserAccount, Logging and etc and warp them in a class which is inherited from DbContext. Every single module has its own entity and model, and every module can be added to main project later, I mean they are not already built. Consider a scenario where I have create a new module, which contains News, Comments and Category entities, I want to plug this to main application, and also use the DbContext defined in core library, but as you know, in Code-First Approach, it will throw an exception, and want me to re-create the database, because the model has changed.

Is there any solution for this problem ? and way to make DbContext extensible ? Somebody suggested GenericRepository but I don`t know how to make it work with my problem (I already use GenericRepository for core entities). Some guy has declared in his question that it is possible with nHibernate. Is it really works for my problem ?

Community
  • 1
  • 1
Babak Fakhriloo
  • 2,076
  • 4
  • 44
  • 80

2 Answers2

0

If your problem is recreating the database you can use SQL migrations for incremental database development. http://www.hanselman.com/blog/EntityFrameworkCodeFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx

Jayantha Lal Sirisena
  • 21,216
  • 11
  • 71
  • 92
0

I found a solution on msdn community : Extending DbContext for modular programming

Babak Fakhriloo
  • 2,076
  • 4
  • 44
  • 80