protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { //someone want the deterministic release of all resources //Let us release all the managed resources this.iPersonaRepository = null; this.iTelefonoRepository = null; } else { // Do nothing, no one asked a dispose, the object went out of // scope and finalized is called so lets next round of GC // release these resources } // Release the unmanaged resource in any case as they will not be // released by GC if (context != null) { context.Dispose(); context = null; } this.disposed = true; } }
/* 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(); } }
public UnitOfWork() { context = new AgendaContext(); disposed = false; }
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(); }