A Good MVC Database First Tutorial

I know there are a lot of examples out there of MVC Code first, but there does not seem to be a whole bunch on Database first.  I did find a really nice one, even though it is a bit old.

Julie Lerman had created a post about Building an MVC3 with Database First and Entity Framework 4.1.

This simple tutorial still applies today, I just did it with Visual Studio 2013 so that would be MVC5 and Entity Framework 6.  There are just a couple gotchas.

Generating Strongly Typed Entity Class

This is the first gotcha.  I picked the EF 6.x DbContext Generator.  Then I discovered that the Model1.Context was redundant so I had to delete it.  I kept the Model1.tt though.

Running the Application

This one was really easy to fix.  In the Global.asax you will find that MVC5 uses the various config.cs files located in the App_Start folder.  So instead of editing your routes in Global.asax just edit them in RouteConfig.cs in the App_Start folder.

There might be better ways to fix these gotchas, especially that first one.  The thing is it worked and is a great little DB First tutorial.

Advertisements

About SheldonS

Web developer for over 15 years mainly with Microsoft technologies from classic ASP to .NET 4. Husband, father, and aspiring amateur photographer.

Posted on February 13, 2014, in MVC and tagged . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: