Esempio n. 1
0
 public static void Guardar(List <T1> entities)
 {
     using (var db = new Datos.COLASEntities())
     {
         foreach (var e in entities)
         {
             db.Set <T1>().AddOrUpdate(e);
         }
         db.SaveChanges();
     }
 }
Esempio n. 2
0
 public static T1 Guardar(T1 entity)
 {
     using (var db = new Datos.COLASEntities())
     {
         db.Set <T1>().AddOrUpdate(entity);
         if (db.SaveChanges() > 0)
         {
             return(entity);
         }
     }
     return(null);
 }
Esempio n. 3
0
        public static bool Eliminar(int pId)
        {
            using (var db = new Datos.COLASEntities())
            {
                db.Configuration.ProxyCreationEnabled  = false;
                db.Configuration.LazyLoadingEnabled    = false;
                db.Configuration.ValidateOnSaveEnabled = false;

                Eliminar(db, pId);
                if (db.SaveChanges() > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 4
0
        public static bool Actualizar(T1 entity)
        {
            using (var db = new Datos.COLASEntities())
            {
                db.Configuration.ProxyCreationEnabled  = false;
                db.Configuration.LazyLoadingEnabled    = false;
                db.Configuration.ValidateOnSaveEnabled = false;

                Actualizar(db, entity);
                if (db.SaveChanges() > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
0
        public static void ActualizarParcial(T1 entity, params Expression <Func <T1, object> >[] properties)
        {
            using (var db = new Datos.COLASEntities())
            {
                db.Configuration.ValidateOnSaveEnabled = false;

                var entry = db.Entry(entity);
                if (entry.State == EntityState.Detached)
                {
                    db.Set <T1>().Attach(entity);
                }

                if (properties != null)
                {
                    foreach (var p in properties)
                    {
                        entry.Property(p).IsModified = true;
                    }
                }

                db.SaveChanges();
            }
        }