Entity Framework Notes
Entity Framework Notes
2) Create new c#.net project and install entity framework using Nugate package manager
console by command
Install-package EntityFramework command.
It will add latest entityframework to your project.
3) To project add ADO.NET Entity Data Model through new item and do the settings. It will
create class containing properties based on table fields
a) It contains context.cs file which contains class context derived from DbContext
containing various members along with
public DbSet<Employee> Employees { get; set; }
4) Create object of Dbcontext class
5) Create object of Employee class
6) Add created object to Employees collection of DbContext
7) Call SaveChanges() methods of DbContext class
As shown below
class Program
{
static void Main(string[] args)
{
var context = new CompanyDBEntities();
var employee = new Employee()
{
Eno=2000,
Ename="Mangesh Jambhale",
Salary=5000,
Dname="computer studies",
Job="teaching",
Econtactno="1234567"
};
context.Employees.Add(employee);
context.SaveChanges();
}
}