• The Entity Framework Database First Approach give an alternative option instead of Code First and Model First approaches to the Entity Data Model .it generate model codes (classes, properties, DbContext etc.) from the selected database.
  • So, Entity Framework database First approach, add new ADO.NET Entity Data Model and Select Generate from database EF Designer model in Entity Data Model Wizard. Following is a simple example of creating a new MVC 4 project using database First approach.
  • Select ADO.NET Entity Data Model from wizard and enter name article tutorial in the Name field.

  • Now Click on Generate from database Entity Data Model Wizard dialog.

  • Following open Generate Database Wizard. You can select existing database or create a new connection by clicking on New Connection. 

  • Select database server and enter the name of the database with credential to create and then click OK.
  • If you want to save connection string check save entity checkbox.

  • Now Select your targeted entity framework.

  • select table ,view and store procedure from DB model as shown below.

  • Click to finish shown below your entity will be created:
  • Now go to solution explorer click on articletutorial.context.cs .
  • shown below your dbcontext.cs



    Now use dbcontext to use insert a record .

    ArticleEntities db = new ArticleEntities();
    Blog blog = new Blog();
     blog.Title = "what is mvc";
    blog.Description = "test";           
    db.Blogs.Add(blog);
    db.SaveChanges();

    Now go to your database select table and see your record will be inserted:

    select * from Blogs

    result:

    Thanks.


0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

Welcome to SQL Tutorials Point

Don't have an account? Click here to Create a new account, it takes less than a minute.