I used the First Entity Framework (EDMX) very successfully and the SQL Server Data Database in combination very successfully - I changed the schema in the database and Update Model from Database to get them in EDMX. I see that Entity Framework 7 will drop the EDMX format, and I'm looking for a new process that will allow me to use Code First in conjunction with database projects.
Many of my existing development and deployment processes depend on having a database project that contains the schema. This happens in the source control, which is deployed along with the code and used to update the production database complete with data migration using scripts before and after deployment. I would not want to leave him.
I would like to split one large EDMX into many smaller models as part of this work. This will mean multiple Code First models that reference the same database.
Assuming I have an existing database and a database project to go with it - I think I will start by using the following wizard to create an initial set of entity classes and contexts - I will do this for each of the models.
Add | New Item... | Visual C
My problem is where do I go from there? How do I handle schema changes? While I can update the database schema, I can use the schema comparison operation to get the changes in the project.
These are the options that I am considering.
- Make changes to the database and use the wizard on top to restore. I assume that I will need to make any changes to the classes of objects and / or context in partial classes so that they are not overwritten. Automate this using a list of tables, etc., It would be convenient. Maybe Powershell or T4 Templates? SqlSharpener (suggested by Kate in the comments), it looks like this might help here. I would also consider disabling everything except checking for database availability and compatibility here, as suggested by Steve Green in the comments.
- Make changes to the code and use migrations so that these changes are applied to the database. From what I understand, without models, a map of clean database schemas (mine does not work) can create problems. I also see some complaints on the network that migration does not apply to all types of database objects - it was also my experience when I played with Code First some time ago - unique restrictions that, I think, were not covered. Is this improved in Entity Framework 7?
- Make changes to the database, and then use migrations as a kind of comparison between the code and the database. See what the differences are and adjust the code. Continue driving until there are no differences.
- Make manual changes to both the code and the database. Obviously, this is not very attractive.
Which one would be better? Is there anything I need to know before trying to implement it? Are there any other better options?
source share