예제 #1
0
            public virtual void Add(T items)
            {
                var context = new WebPixContext();

                context.Entry(items).State = EntityState.Added;
                context.SaveChanges();
            }
예제 #2
0
            public virtual void Remove(params T[] items)
            {
                var context = new WebPixContext();

                foreach (T item in items)
                {
                    context.Entry(item).State = EntityState.Deleted;
                }
                context.SaveChanges();
            }
예제 #3
0
            public virtual T GetSingle(Func <T, bool> where,
                                       params Expression <Func <T, object> >[] navigationProperties)
            {
                T              item    = null;
                var            context = new WebPixContext();
                IQueryable <T> dbQuery = context.Set <T>();

                //Apply eager loading
                foreach (Expression <Func <T, object> > navigationProperty in navigationProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

                item = dbQuery
                       .AsNoTracking()         //Don't track any changes for the selected item
                       .FirstOrDefault(where); //Apply where clause

                return(item);
            }
예제 #4
0
            public virtual IList <T> GetAll(params Expression <Func <T, object> >[] navigationProperties)
            {
                List <T> list;
                var      context = new WebPixContext();

                IQueryable <T> dbQuery = context.Set <T>();

                //Apply eager loading
                foreach (Expression <Func <T, object> > navigationProperty in navigationProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

                list = dbQuery
                       .AsNoTracking()
                       .ToList <T>();

                return(list);
            }