Updating a Classic

This week I went searching for a classic ASP.NET MVC example that I could use as a basis for making further modifications in future articles. I found an old example Movie Database Application from 2009 that I decided to use. Its features include listing movies from a database, creating new movie entries, and editing existing movie entries. Admittedly, it is not a full-featured application, but it does at least give one a starting point to try to understand how to accomplish some simple goals quickly using ASP.NET MVC.

As I mentioned, the article was written in 2009, so there have been a lot of changes since then. The screenshots were taken using Visual Studio 2008. I decided to refresh the example, using Visual Studio 2015 and ASP.NET MVC 5. Given the release date of the article, it appears that the article was written using ASP.NET MVC 1.0.

The purpose of this article is to share my updated version of this classic example and to discuss a few of the differences that I encountered in recreating it with ASP.NET MVC 5. Although the differences were not extensive, they would be enough to trip up a novice trying to follow along at this point. Granted, there are likely plenty of other newer examples, but I felt like this simple example was a good fit for my planned usage in future articles.

First, you would now use one of the Visual Studio Community versions. 2017 is the newest, but I already had 2015 installed, so I went with that. The feature set of these free versions is quite impressive given the bargain price tag. Given that you would be using a different version of Visual Studio, many of the dialogs are slightly different. However, the differences are quite minor considering that nearly ten years has passed.

Second, creating an Entity Framework (EF) data model has changed slightly, but again the change is very minor. The thing that stood out to me was the fact that EF6 is now trying to come up with appropriate singular names for the objects based upon the plural naming of the database table. In my case, it tried to rename the Movies table to Movy. This update would probably work for a number of different nouns, so it’s understandable why they took that approach.

Third, the generated views now use Razor instead of ASPX. I am of a similar opinion to a lot of developers that Razor is easier to work with, so this is a bonus. Razor became the default view engine with ASP.NET MVC 3, so it makes sense that this would now be the case. Although these views like a fair amount different from those given in the example, they are all generated, so the impact on creating the project is virtually none.

Finally, the biggest difference that I found in this example was that the EF editing code needed to be updated to work with EF6. Some of the methods called in the example, such as ObjectContext.ApplyPropertyChanges, are no longer available. I had to end up replacing the code for adding records to the database and updating records in the database.

Below is the controller method that I used to handle creating a movie record in the database. This includes the updated EF methods necessary to make this work with EF6.

The following is the controller method that I used to handle updating a movie record in the database. Again, this includes updated EF methods needed to make this work with EF6.

All in all, the process of getting this classic example running with ASP.NET MVC5 in Visual Studio 2015 was accomplished with little difficulties. I consider this to be somewhat impressive, given that the example is nearly ten years old. I will be using this refreshed version of the example in some future articles to demonstrate various features of ASP.NET MVC.

 

One thought on “Updating a Classic

  1. Pingback: To Test Or Not To Test | I Want My MVC

Leave a Reply