Thursday, October 16, 2014

Project: No easy way to change class names using EF or MVC

I am still testing around the MVC and EF tools. What I have been trying is to change a class name. Although this probably happen very rarely, this exercise at least helped me understand how some of the pieces fit together.

It was interesting that the cshtml are not included in the global name change updates. I had to manually go through each one to update to the new class name. I also noticed that all the model parameters always have the red squiggly underline. This does not have an impact as I was able to eventually get the site running again.

Clearly, this is an example that is kind of the drawback to scaffolding (sorry, still not completely familiar with the term yet). Because a lot of the code is generated based on the class name and because they are internal variables, these variable names do not change. This is not a major problem for the code as it will still render but will be just as misleading as they would still reference the old class name. This also includes the documentation. The best way is probably use the Visual Studio's CTRL+ALT+F feature to just replace all terms. Hopefully, the term is not too simplistic to impact other variables.

Somehow my table name was updated with the new model name. I am not exactly sure how I did this or when it happened as I was not checking that while I was correcting the files. I did run an Update-Database. This is my best guess on when it possibly could have occurred. Later, I did an Add-Migration and Update-Database. But because the Up/Down methods were empty, I assumed there were no changes.

At then end of the day, it is possible. I'm not sure how complex some of these classes may become, but with simple classes, it is much easier just to recreate a new class. I'm sure there probably is a way to delete the old tables. Hopefully, you just never have to make these changes.

No comments:

Post a Comment