Tech Junkie Blog - Real World Tutorials, Happy Coding!: End-to-End ASP.NET MVC 5 : Create Entity Data Model With Entity Framework

Saturday, June 18, 2016

End-to-End ASP.NET MVC 5 : Create Entity Data Model With Entity Framework

In our previous blogs we've created an ASP.NET MVC from scratch.  In this blog we are going to use Entity Framework as the ORM (Object Relational Mapping) as a conduit to our database, so that we can query our data as an object.  An ORM as the name implies maps database tables, views, and stored procedures as objects in a programming language so that developers can work with the data as objects.

Step-by-Step Instructions:

1.  First we need to add the Entity Framework 6.1.3 to our ASP.NET MVC, we accomplish by right-click on "References" then select "Manage NuGet Packages"















2. On the search box type in "EntityFramework" no spaces, in the search result click on the "Install" button next to the "EntityFramework" package.











3.  Click "I Accept" on the "Licence Acceptance" screen




























4. Click "Close"






5.  Once the "EntityFramework" package has been added you will see a green checkmark next to the "EntityFramework" search result.











6.  If you look at the "References" in the project you will now see the EntityFramework references










7.  Now we are ready add a database model to our project.  We will add the "Northwind" database to our project.  Right-click on the "Models" folder, then select "Add" → "New Item"




















8.  Select "Data" on the left pane under "C#" then select "ADO.NET Entity Data Model" the main pane















9. In the "Name" field for the item type "NorthwindModel"





10. Click the "Add" button





11.  On the "Choose Model Contents" screen, select "EF Designer from database"











12. On the "Connection Properties" screen, click on the "New Connection" button






13. In this screen select type in the SQL server name, or select it from the "Server name" dropdown list.  Then type "Northwind" or select it from the "Select or enter a database name" dropdown list.  Then click "OK".  If you don't have the Northwind database in your database server, you can follow the instructions in this blog to add it.








































14. All the database connection information should be configured correctly in the "Entity Data Model Wizard" now.  Click "Next"



15.  For the database objects to include, select "Tables", "Views", and "Stored Procedures and Functions" then click "Finish"


16.  The Entity Framework models and classes are now added to the project.

17.  If you click on the "NorthwindModel.edmx" file the model will be visually presented in the model designer editor

























18.  Build the project, and that's it

5 comments:

  1. Do you wish to buy the best scope for Best budget Scope for AR 15 under $100? ? It is true that people loves to hunt wild animal. However, you must have a complete accessory for hunting. We know that the most used guns are AR 15.

    ReplyDelete
  2. excellent post, very informative. I wonder why the other experts of this sector don’t notice this. You should continue your writing. I am confident, you have a huge readers’ base already! 메이저사이트

    ReplyDelete
  3. Wonderful post however , I was wanting to know if you could write a litte more on this subject? I’d be very grateful if you could elaborate a little bit further. Bless you! 온라인경마

    ReplyDelete
  4. UK assignment help is an in-depth study, whereas education justice is almost the same. It is a study of the policies, rules, and regulations of the courtrooms. When you lack the knowledge to complete your coursework assignments, never be afraid to seek assignment help online. I'm telling you not to be hesitant because there are still people who think twice or three times before hiring a professional writer to complete their homework.

    ReplyDelete

Search This Blog