Exemplo n.º 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();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (var e = new AdventureWorksEntities())
            {
                Object o = null;

                var k = new EntityKey("AdventureWorksEntities.Contatos", "ContactID", 1);

                if (!e.TryGetObjectByKey(k, out o)) goto fim;

                var c = o as Contato;

                if (c == null) goto fim;

                c.Nome += "*";

                Console.WriteLine("{0} {1}", c.Nome, c.Sobrenome);

                e.SaveChanges();
            }

            fim: //não usar label... isso é só uma brincadeira...
            Console.ReadKey();
        }