1

We use model first for tables and relations and database first for views and stored procedures.

If we change the model we have to:

-generate database

-create views and procedures

-add the procedures and the views to the model

-remap function call of procedures manually

This costs much time because the model changes often or has failures.

Does anyboy knows a workaround to automatically integrate the views and procedures in the model?

5
  • 1
    Switching to database first would take care of points 1 and 3 (and 2 partly), because then you do modifications only in the database and update the model. You're going to have to write stored procedures anyways. I think it's hard to automate the mapping part. Commented Oct 23, 2013 at 8:08
  • that helps a lot saving time on changing stuff for one developer. The other teammates still have to do the whole stuff when they get lastest changes on their machines. Commented Oct 23, 2013 at 14:11
  • we also could use central database instance to generate div scripts or whatever, but if the model Generator would be able to integrate our view/procedure generate script it would be very very nice Commented Oct 23, 2013 at 14:16
  • I don't think you can do that with model-first. As for your first comment, can't you guys share a database backup, or deploy change scripts? Commented Oct 23, 2013 at 14:29
  • Not really, we also need dummy data to develope. We have a dummy data generator but if somebody developes a feature he may need to change the data to test behavior etc. That would blow up our whole development workflow. Commented Oct 25, 2013 at 11:36

1 Answer 1

1

You could automate the process by creating your own template for generating DDL from SSDL. By default EF designer uses SSDLToSQL10.tt file but you could create your own .tt file which would generate DDL that better suits your needs. This should address 1) and 2). Once you have the database you could now update your model from the database. This should adress 3). Finally to address 4) you could write a Model Generation Extension that would tweak the model the designer builds from the database in the OnAfterModelGenerated/OnAfterModelUpdated method. (Be aware - some of the extension points in the designer are weird to say the least and might be confusing/hard to implement).

Another option you may want to explore is to use Code First and Migrations. With Migrations you could evolve your database instead of constantly creating/deleting it. If you need, you can use SQL to define a migration so you have full control of how your database looks like. Code First does not support some of the features supported by ModelFirst/DatabaseFirst (e.g. TVFs/FunctionImports) so you may want to check first if what's supported is enough for you.

Sign up to request clarification or add additional context in comments.

2 Comments

Just to be clear. The main problem is that generate database recreates the table mapping. But this function creates Tables for the entities that were brought from database by updating the model. So the mapping is not correct anymore and we delete and readd the views, so the mapping is correct again. I can manipulate the tt script, so it doesn't create tables for entites with the view prefix anymore. But then instead of the wrong mapping no mapping will be created for the views and procedures.
My plan (at the moment) could be this: 1. generate database and views and procedures - find a way to update the model automatically after this step. Or 2. Find a way to generate database without dropping the whole entity mapping.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.