Tuesday, 16 September 2014

LINQ Crud Operation With Entity Framwork

                   
Insert the record :


EntityDB dataBase = new EntityDB();
Customer c = new Customer
{
     Name = "Test",
     Gender = "Male
};
dataBase.Customers.AddObject(c);
dataBase.SaveChanges();

Delete the record : 
Customer c = (from x in dataBase.Customers
             where x.Name == "Test"
             selext x).First();
dataBase.Customers.DeleteObject(c);
dataBase.SaveChanges();

Update the Record : 

Customer c = (from x in dataBase.Customers
             where x.Name == "Test"
             selext x).First();
c.Name = "New Name";
dataBase.SaveChanges();

No comments:

Post a Comment