public static void ManuPeople(people _People) { peopleDataContext dc = new peopleDataContext(); { // here we have the update or Insert //// -- var findPeople = getPeopleID(_People.Id); var findPeople = (from gente in dc.GetTable <people>() where (gente.Id == _People.Id) select gente).SingleOrDefault <people>(); if (findPeople == null) { try { people people = new people(); people.Id = _People.Id; people.name = _People.name; people.phone = _People.phone; people.age = _People.age; Table <people> peopleInsert = GetPeople(); peopleInsert.InsertOnSubmit(people); peopleInsert.Context.SubmitChanges(); } catch (Exception) { // better way, because you can capture ALL exception and use it as IS throw; } } else { try { //use the findPeople on CONTEXT findPeople.Id = _People.Id; findPeople.name = _People.name; findPeople.phone = _People.phone; findPeople.age = _People.age; dc.SubmitChanges(); } catch (Exception) { // better way, because you can capture ALL exception and use it as IS throw; } } } }
partial void Updatepeople(people instance);
partial void Deletepeople(people instance);
partial void Insertpeople(people instance);