Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Code First Approach in ASP.NET MVC:-



It is Ado.NET Entity Framework mapping pattern which is used to create entity framework schema and Table class using code, We will only set entity framework environment and all code part will be managed by Code First Approach,


We will manually create  DataContext Class and Provide Connection String Under it after that we will Create Model Class to declare Table name and Table Column name.


Step for Code First Approach:-


1)  Create Model Class and Define set of properties to define column.
[Table("Student")]
    public class Student
    {
        [Key]
        public int Rno { get; set; }
        public String Sname { get; set; }
        public String Branch { get; set; }
        public int Fees { get; set; }
    }
2)  Add ADO.NET Entity Framework in Project.

3)  Create DataContext class and Define Table and Connection String.
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace MvcApplication3.Models
{
    public class StudentDB:DbContext
    {
        public StudentDB()
        {
        }
        public DbSet<Student> Students { get; set; }
    }
}
4)  Implement CRUD Operation using Scaffolding or By Scratch.









Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post