• 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.
  • What Is Database First Approach In Entity Framework
  • Now Click on Generate from database Entity Data Model Wizard dialog.
  • What Is Database First Approach In Entity Framework
  • Following open Generate Database Wizard. You can select existing database or create a new connection by clicking on New Connection. 
  • What Is Database First Approach In Entity Framework
  • Select database server and enter the name of the database with credential to create and then click OK.
  • What Is Database First Approach In Entity Framework
  • If you want to save connection string check save entity checkbox.
  • What Is Database First Approach In Entity Framework
  • Now Select your targeted entity framework.
  • What Is Database First Approach In Entity Framework
  • select table ,view and store procedure from DB model as shown below.
  • What Is Database First Approach In Entity Framework
  • Click to finish shown below your entity will be created:
  • What Is Database First Approach In Entity Framework
  • Now go to solution explorer click on articletutorial.context.cs .
  • What Is Database First Approach In Entity Framework
  • shown below your dbcontext.cs

    What Is Database First Approach In Entity Framework

    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:

    What Is Database First Approach In Entity Framework

    Thanks.


comments


Leave a comment

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

You may also like