Beispiel #1
0
        private static void DeleteContact()
        {
            ContactsDBDataContext db = new ContactsDBDataContext();
            var deleteContact        = db.Contacts.Where(c => c.Name == "HermoineGranger").First();

            db.Contacts.Remove(deleteContact);
            db.SaveChanges();
        }
Beispiel #2
0
        //-----------------applies to DB first -----------------------

        private static void UpdateContact()
        {
            // Update
            ContactsDBDataContext db = new ContactsDBDataContext();
            var contactUpdate        = db.Contacts.Find(23);

            contactUpdate.Gender = "Male";
            db.SaveChanges();
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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;
        }