UserEntities objUserEntities= new UserEntities();/*Create object of user entity
/* Add records into the database */
public void AddUser(User objUser)
{
objUserEntities.AddToUsers(objUser); /*Linq has its own function to insert the record Add()*/
objUserEntities.SaveChanges();/*This function save the changes to the database*/
}
/* Update the records into the database */
public void EditRecords(Details1 objDetail)
{
Details1 Details= (from o in objUserEntities.Details1 where o.ID==objDetail.ID select o).SingleOrDefault(); /*Get the records which we have to edit*/
/*Edit the records*/
Details.Name=objDetail.Name;
Details.Phoneno=objDetail.Phoneno;
Details.Address=objDetail.Address;
objUserEntities.SaveChanges(); /*Save the changes to the database*/
}
/*Delete records into the database */
public List DeleteDetails(int id)
{
Details1 objDetails= (from o in objUserEntities.Details1 where o.ID==id select o).SingleOrDefault();/*Get the records which we have to delete*/
objUserEntities.DeleteObject(objDetails);/*Linq has its own function to delete the records DeleteObject()*/
objUserEntities.SaveChanges();/*Save the records into the database*/
}
0 Comment(s)