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())
            {
                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();
        }