I am new to ASP.NET MVC 4 and Web API.
What I want to achieve is to create a CRUD web application that is able to manipulate the data tables in a simple existing SQL Server 2008 database.
I thought about the new MVC 4 with Web API and Entity Framework. There are a number of samples and examples about code first data access pattern but very few about database first.
Can anyone help with any brief idea how to achieve this with database first and Entity Framework and repository pattern please?
I started down this path a few months ago: learning ASP.Net, MVC3, using an existing database to build an App.
This is what I found (I'm happy to be corrected):
Don't learn VB, learn C#. There are very few VB samples around.
I followed a 'database first' tutorial. There are many tutorials on the web, just get started and follow one and don't be afraid to start over
It turns out that MVC is a bit of a misnomer. Often you need 5 layers, not 3:
Model (The M in MVC, generally generated for you by some code generation tool like Entity Framework, maps directly to tables)
ViewModel (wrapper classes around your autogenereated table classes that add more useful data) - this post is where I came accross them: MVC dbContext find parent record when current record has no elements
Controller (The C in MVC)
View (The View in MVC)
Like I say I'm happy to be corrected on any of these points. This is just my viewpoint at this stage of my journey. I have to say I have only investigate jqGrid as a grid solution and I'm just about ready to try something else.
What you've described (CRUD operations, SQL Server, Entity Framework) is the assumed default for MVC4 projects. This should be very straightforward for you to set up given a database-first approach.
Modelsfolder, create a new Entity Framework class (ADO.Net Entity Framework Model). Choose "generate from database" and follow the instructions
Controllersfolder and add a new controller. Choose "MVC controller with read/write actions and views, using Entity Framework". For the Model class, select the table entities you want to target. For the Data context class, select the Entity Framework class you created in step 2.
That's it. You should be able to run the project and have scaffolded CRUD forms fully operational (navigate to /YourControllerName to see a list of rows from the table). You can repeat step 4 as needed to add other table controllers.