using multiple model files in solution

Mar 2, 2011 at 7:54 PM

Is it safe to use multiple model files in the same solution?

Before generating an install project to update the database i got a warning message that it may cause database versioning issues.

Splitting entities in more than 1 model helps to more logically partition the application.

But will it cause me more issues later on ?

Generally what best practices do you propose to handle lots of tables , splitting or puting everything in one model ?


Mar 9, 2011 at 11:59 PM

I do this all the time. Just make sure that the project name is different in each model. You can then generate multiple DAL API projects and database tracking projects. I have a Framework solution with like 8 models in it. this creates 8 APIs and 8 database projects. There are no issues as long as you unique name the models. Remember 1 model 1 database. If you need multiple databases then create multiple models.

Mar 13, 2011 at 12:14 PM

yes, i followed your instructions .

I have 3 models in a solution that generate 3 dal projects and 3 database.install projects.

the 3 database projects  all point to the same physical database .

so i run the first database project and database is populated . when i attempt to run the

second database project i get the warning message that it may cause database versioning issues. 

can i simply ignore the message and update the database  even though the first version of the database was created with a different  database.install project?

will it cause issues if i re-run the first database project to update and so on ?


Mar 13, 2011 at 2:49 PM

Yes you can ignore the error but it is there for a reason. First when you create or update a database the model GUID and version is stored with the database. If you update a second or third model you are really overwriting this setting. In other words you are are loosing all the versioning. Also if you have tables with the same name in the different models you will most likely cause problems for yourself. The database installer projects are designed to control a single database. Since you are using multiple models on the same database you are loosing the versioning and upgrade abilities of the nHydrate framework. I advise you to keep 3 databases for your three models (as designed) or have one model file. What you are doing is essentially by passing the whole reason to use the framework in the first place which is keeping your model in sync with your database.

Mar 13, 2011 at 3:55 PM

thanks for your thorough explanation.