Пример #1
0
        //public static List<T1> Listar()
        //{
        //    using (var db = new VENDIXEntities())
        //    {        //        return db.Set<T1>().ToList();
        //    }
        //}

        public static List <T1> Listar(
            Expression <Func <T1, bool> > filter = null,
            Func <IQueryable <T1>, IOrderedQueryable <T1> > orderBy = null,
            string includeProperties = "")
        {
            using (var db = new YARIEntities())
            {
                db.Configuration.ProxyCreationEnabled  = false;
                db.Configuration.LazyLoadingEnabled    = false;
                db.Configuration.ValidateOnSaveEnabled = false;

                IQueryable <T1> query = db.Set <T1>();
                if (filter != null)
                {
                    query = query.Where(filter);
                }

                foreach (var includeProperty in includeProperties.Split
                             (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    query = query.Include(includeProperty);
                }

                if (orderBy != null)
                {
                    return(orderBy(query).ToList());
                }

                return(query.ToList());
            }
        }
Пример #2
0
        public static T1 Obtener(int id)
        {
            using (var db = new YARIEntities())
            {
                db.Configuration.ProxyCreationEnabled  = false;
                db.Configuration.LazyLoadingEnabled    = false;
                db.Configuration.ValidateOnSaveEnabled = false;

                return(db.Set <T1>().Find(id));
            }
        }
Пример #3
0
 public static void Guardar(List <T1> entities)
 {
     using (var db = new YARIEntities())
     {
         foreach (var e in entities)
         {
             db.Set <T1>().AddOrUpdate(e);
         }
         db.SaveChanges();
     }
 }
Пример #4
0
 public static T1 Guardar(T1 entity)
 {
     using (var db = new YARIEntities())
     {
         db.Set <T1>().AddOrUpdate(entity);
         if (db.SaveChanges() > 0)
         {
             return(entity);
         }
     }
     return(null);
 }
Пример #5
0
        public static void ActualizarParcial(T1 entity, params Expression <Func <T1, object> >[] properties)
        {
            using (var db = new YARIEntities())
            {
                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();
            }
        }