Example #1
0
        static void Main(string[] args)
        {
            using (var e = new AdventureWorksEntities())
            {
                var c = e.Contatos.FirstOrDefault(x => x.ContactID == 19978);

                c.Nome += "#";

                Console.WriteLine(c.Nome);

                e.SaveChanges();

                Console.WriteLine(c.Nome);

                e.Detach(c);

                c.Nome += "@";

                var key = e.CreateEntityKey("Contatos", c);

                object o;

                if (e.TryGetObjectByKey(key, out o))
                {
                    e.ApplyCurrentValues(key.EntitySetName, c);
                    e.SaveChanges();
                }

                Console.WriteLine(e.Contatos.FirstOrDefault(x => x.ContactID == 19978).Nome);
            }

            Console.ReadKey();
        }
Example #2
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();
     }
 }