Firstly,you need to install entityframework from "Manage Nuget Packages for Solution".
Model Class:
Company.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Database_First_Approach.Models
{
[Table("tblCompany")]
public class Company
{
public int id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
}
}
CompanyContext.cs:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace Database_First_Approach.Models
{
public class CompanyContext:DbContext
{
public DbSet<Company> companies { get; set; }
}
}
Then make a connection file with your database and add some line into your Web.config file:
<add name="CompanyContext" connectionString="Data Source=DESKTOP-UTTQQQ1;Initial Catalog=LockDownExample;Integrated Security=True" providerName="System.Data.SqlClient" />
Then add "MVC5 Controlller with views,using Entity Framework then add model class which is Company then add Data Context Class which Company context after click add button it will create automatically INSERT,UPDATE,DELETE,DETAILS functionality.
Click here to learn about SignIn and SignUp
Model Class:
Company.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Database_First_Approach.Models
{
[Table("tblCompany")]
public class Company
{
public int id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
}
}
CompanyContext.cs:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace Database_First_Approach.Models
{
public class CompanyContext:DbContext
{
public DbSet<Company> companies { get; set; }
}
}
Then make a connection file with your database and add some line into your Web.config file:
<add name="CompanyContext" connectionString="Data Source=DESKTOP-UTTQQQ1;Initial Catalog=LockDownExample;Integrated Security=True" providerName="System.Data.SqlClient" />
Then add "MVC5 Controlller with views,using Entity Framework then add model class which is Company then add Data Context Class which Company context after click add button it will create automatically INSERT,UPDATE,DELETE,DETAILS functionality.
Click here to learn about SignIn and SignUp
Comments
Post a Comment