Esempio n. 1
0
        public virtual IList <T> GetList(Func <T, bool> where, params Expression <Func <T, object> >[] navProperties)
        {
            List <T> list;

            using (var context = new CognizantContext())
            {
                IQueryable <T> dbQuery = context.Set <T>();

                foreach (Expression <Func <T, object> > navigationProperty in navProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

                list = dbQuery.AsNoTracking().Where(where).AsQueryable <T>().ToList <T>();
            }

            return(list);
        }
Esempio n. 2
0
        public virtual T GetSingle(Func <T, bool> where, params Expression <Func <T, object> >[] navProperties)
        {
            T item = null;

            using (var context = new CognizantContext())
            {
                IQueryable <T> dbQuery = context.Set <T>();

                foreach (Expression <Func <T, object> > navigationProperty in navProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

                item = dbQuery.AsNoTracking().FirstOrDefault(where);
            }

            return(item);
        }
Esempio n. 3
0
        public virtual IList <T> GetAll(params Expression <Func <T, object> >[] navProperties)
        {
            List <T> list;

            using (var context = new CognizantContext())
            {
                IQueryable <T> dbQuery = context.Set <T>();

                if (navProperties != null)
                {
                    dbQuery = navProperties.Aggregate(dbQuery, (current, include) => current.Include(include));
                }

                foreach (Expression <Func <T, object> > navigationProperty in navProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

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

            return(list);
        }