Tutorials for ASP.NET mvc database first
Solution 1
Here you could try this examples:
Building an MVC 3 App with Database First and Entity Framework 4.1, video is here
Entity Framework Database First in MVC3 1of3, this is a youtube video
Database First Approach in Entity Framework, this is an example on MVC4
Hope this helps.
Solution 2
You can create a BaseController
class from which all of your other controllers can inherit.
In the BaseController
, create a DbContext
called db
or something easy to remember and easy to access.
Something like this:
public abstract class BaseController : Controller
{
protected readonly MyEntities db;
public BaseController()
{
db = new MyEntities();
}
}
MyEntities
is of course going to refer to the Entity Model you generated.
I found this extremely useful in a big project I'm wrapping up at work.
Hope this helps.
Solution 3
You should be able to use the Entity Data Model Wizard to import your database and auto-generate the EDMX file which generates classes for you. See this example:
http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/database-first-approach-in-entity-framework/
user2524908
Updated on June 04, 2022Comments
-
user2524908 about 2 years
Attempting to use asp.net for the first time. Need to create a asp.net mvc api which provides GET API for like 5 tables returning 1 column. Pretty simple stuff. I am however having a difficult time bringing everything together. I was able to create a tutorial on a simple mvc and call a service to return static data from a model. I was also able to use EF5 to generate the models, but from here I was unsure how to connect them to my Controller to get the data.
So my question. Does anyone know of a sample which is database first then shows how to use that "imported" database in some sort of MVC api?
-
user2524908 over 10 yearsThanks for the links on the tutorials. very very new to asp.net. I will try those out. Just having some disconnect about how to take those and turn them into the MVC API that I need.
-
user2524908 over 10 yearsThanks for the information. I am going to dive into these tutorials, however I am very new to asp. What I am doing is really simple. Just need to create a web api which has restful web service that performs simple select on 5 tables. www.test.com/Controller1&val=1234. maybe berform select * from table where id=1234. And then return it as json or xml