private static void DeleteContact() { ContactsDBDataContext db = new ContactsDBDataContext(); var deleteContact = db.Contacts.Where(c => c.Name == "HermoineGranger").First(); db.Contacts.Remove(deleteContact); db.SaveChanges(); }
//-----------------applies to DB first ----------------------- private static void UpdateContact() { // Update ContactsDBDataContext db = new ContactsDBDataContext(); var contactUpdate = db.Contacts.Find(23); contactUpdate.Gender = "Male"; db.SaveChanges(); }
private static void Add() { //Add new contact Contact c = new Contact(); c.Name = "HermoineGranger"; c.Loc = "England"; c.Gender = "F"; c.Email = "hermoinegmailcom"; ContactsDBDataContext db = new ContactsDBDataContext(); db.Contacts.Add(c); db.SaveChanges(); }
private static void GetAllContacts() { ContactsDBDataContext db = new ContactsDBDataContext(); // to write from DB db.Database.Log = Console.WriteLine; var allContacts = db.Contacts; //foreach (var item in allContacts) //{ // Console.WriteLine(item.Name); //} var allBoys = from contact in db.Contacts where contact.Gender == "Male" select contact; }