Exemplo n.º 1
0
 public void UpdateContact(Contact c)
 {
     using (var e = new AdventureWorksEntities())
     {
         e.Attach(e.Contacts.Single(x => x.ContactID == c.ContactID));
         e.ApplyCurrentValues("Contacts", c);
         e.SaveChanges();
     }
 }
Exemplo n.º 2
0
        public void DeleteContact(Contact c)
        {
            if (c == null) return;

            using (var e = new AdventureWorksEntities())
            {
                e.Attach(c);
                e.DeleteObject(c);
                e.SaveChanges();
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            using (var e = new AdventureWorksEntities())
            {
                var c = e.Contatos.First();

                Console.WriteLine(c.EntityState);

                e.Attach(c);

                Console.WriteLine(c.EntityState);

                c.Nome = "Gustavo";

                Console.WriteLine(c.EntityState);

                e.Detach(c);

                Console.WriteLine(c.EntityState);
            }

            Console.ReadKey();
        }