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?
The Database First Approach provides an alternative to the Code First and Model First approaches to the Entity Data Model. It creates model codes (classes, properties, DbContext etc.) from the database in the project and those classes become the link between the database and controller.
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the . NET Framework.
It's really difficult to try and learn an entirely new language/framework under pressure. If you're required to deliver working software for your day job, trying to learn ASP.NET Core at the same time might be heaping too much pressure on yourself.
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.
Models
folder, create a new Entity Framework class (ADO.Net Entity Framework Model). Choose "generate from database" and follow the instructionsControllers
folder 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.
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
If you want anything remotely flashy you need to use JQuery - this is basically a javascript library. MVC / ASP.Net offers very little in the way of interactive grids and pages.
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)
Javascript (If you want anything beyond a basic HTML form, like a gird or a date picker you need to use javascript)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With