Tuesday, April 17, 2012

MVC 4 / Firebird / EF 4.1 and Database First

My first blog and it's about giving back to the community I've received so much from.
Recently decided to concentrate my efforts on MVC4, Entity Framwork 4.1 and Firebird after spending a year trying to master Silverlight with MVVM. A recent post on Single Page Application Overview By Brad Severtson led me to his great presentation given by Steve Sanderson (http://channel9.msdn.com/Events/TechDays/Techdays-2012-the-Netherlands/2159). As I'm more interested in Database First development and given that code first is the preferred method shown in examples, I decided to try and convert the beta example with Firebird and Database First. The results of my journey are below. Products used: Microsoft MVC4 Beta with the latest SPA templates, Firebird 2.5 and Firebird 2.7.5 asp dotnet drivers.
Preexisting Firebird database used in my examples.
Metadata view
Data View

Start of new MVC 4 app / Name=SPA1

Template selection

Nuget update for SPA template

Restart solution
Delete automatically created todoitem page not begin used or create todo table in database.
Add the Model

Make sure you arUsing EF 4.1 and Select ADO.NET Entity Data Model

I uesd an established connection fromVS2010
Use SPA1Context for all naming
Select a few Tables. Products used in test

Make all keys Identity type
Code generation item to make a simple DB Context.
Select ADO.Net DbContext
A review of model

This is what got created.

Must do a build before using Controllers
Add new Controller
Select options for dropdowns

Important to select SPA1ContextEntities

Generated javascript
Generated c#
Generated View

Web Config

Product Index

Add Product to Main Menu in _Layout.cshtml

Default page When testing new website

Products Page

Edit to change a product. No postbacks occur.

A view of changed products before saving. All modified rows are hi-lighted

View after pressing save button

View of data stored in table
The End.