Code First Approach in ASP.NET MVC

0
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.









Tags

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)