示例#1
0
        /* Persona mPersona2;
           using (AgendaContext ctx = new AgendaContext())
           {
               mPersona2 = ctx.Set<Persona>().Find(2);
              // mPersona2.Nombre = "Hola";
           }

           using (AgendaContext ctx = new AgendaContext())
           {
               ctx.Entry(mPersona2).State = EntityState.Modified;
               ctx.SaveChanges();
           }*/
        static void UpdateSinRepo()
        {
            Random lRandom = new Random();
            Persona mPersona2;

            using (AgendaContext ctx = new AgendaContext())
            {
                int cant = ctx.Set<Persona>().Count<Persona>();
                lRandom.Next(0, cant - 1);
                mPersona2 = ctx.Set<Persona>().ToList<Persona>()[lRandom.Next(0, cant - 1)];
            }
            mPersona2.Nombre = "Ramiro estuvo aqui";
            using (AgendaContext ctx = new AgendaContext())
            {
                ctx.Entry(mPersona2).State = EntityState.Modified;
                ctx.SaveChanges();
            }
        }
示例#2
0
        static void LeerSinRepo()
        {
            Persona mPersona2;
            List<Persona> pLista = new List<Persona>();
            using (AgendaContext ctx = new AgendaContext())
            {
                DbSet<Persona> dbset = ctx.Set<Persona>();

                mPersona2 = dbset.Find(1);
                pLista = dbset.Include(p => p.Telefonos).ToList<Persona>();
                MostrarPersona(mPersona2);

                // mPersona2.Nombre = "Hola";
            }
            MostrarTodos(pLista);

            Console.ReadKey();
        }