Search This Blog

Thursday, March 31, 2016

Finished the migration to code first

Small steps after small steps I managed to migrate my code from one design type to another. I know I know some of you may wonder why I stick to this idea to convert the kind of "database first" to "code first" but the point is => keep the project maintainable. By having all the login in CS code and not in a mixed CS and XML with the CS being generated it helps us to keep track of the changes.

The migration was a lot more painful than planned, and I'm sure the story is not over, but at least from what I can see it seems to work as well as before.

I can't be happy enough about our integration tests which helped me to iron out a huge number of issues, and would not even have tried to do this change without the tests. Why? It's a question of confidence and consequences. Just being able to compile a code doesn't mean it is correct and as the software grows so does the complexity (at least usually). In my case testing all by myself is impossible, and having tests checking a good chunk of the functionalities helps.

I can now continue to work on adding more features and squashing older open issues.

For those willing to take the same road as me:
- Use the T4 macro which generates your object classes by modifying the TT file and adding the needed attributes.
- Use the embedded Visual Studio debugger of your T4 files => place a break-point where you want on the template then right click on the TT file and choose debug.
- You will need to have key, key generator, foreign key and table name attributes.
- Many info will require you to use the EDMX file as XML with a XPATH to dig the values out of it.
- Finally change the links for many to many and one to one links inside the OnModelCreating function of your DbContext class.

The road is possible, but it doesn't mean it is always simple. If your project has only a few table then certainly it makes the thing easier, if like me you have over 120 tables, then it takes more time to ensure all works and is correctly done.

No comments:

Post a Comment