示例#1
0
        public virtual IList <T> GetList <T>(Expression <Func <T, bool> > where, params Expression <Func <T, object> >[] navigationProperties) where T : class
        {
            IList <T> list;

            using (var db = new DbCtx(_dbContextName))
            {
                list = GetList <T>(db, where, navigationProperties);
            }

            return(list);
        }
示例#2
0
        public virtual T Get <T>(Expression <Func <T, bool> > where, params Expression <Func <T, object> >[] navigationProperties) where T : class
        {
            T item;

            using (var db = new DbCtx(_dbContextName))
            {
                item = Get <T>(db, where, navigationProperties);
            }

            return(item);
        }
示例#3
0
        public virtual IList <T> Search <T>(string term, params Expression <Func <T, object> >[] navigationProperties) where T : class
        {
            IList <T> list;

            using (var db = new DbCtx(_dbContextName))
            {
                var objectSet = ((IObjectContextAdapter)db).ObjectContext.CreateObjectSet <T>();

                foreach (Expression <Func <T, object> > navigationProperty in navigationProperties)
                {
                    objectSet = objectSet.Include <T, object>(navigationProperty);
                }
示例#4
0
        public virtual PaginatedResult <T> GetPaginated <T>(int page, int limit, Expression <Func <T, bool> > where, params Expression <Func <T, object> >[] navigationProperties) where T : class
        {
            PaginatedResult <T> result = new PaginatedResult <T>();

            using (var db = new DbCtx(_dbContextName))
            {
                result.Total = Count <T>(db, where, navigationProperties);
                result.Items = GetPaginated <T>(db, page, limit, where, navigationProperties);
                result.Page  = page;
                result.Limit = limit;
            }

            return(result);
        }
示例#5
0
        private IList <T> GetList <T>(DbCtx db, Expression <Func <T, bool> > where, params Expression <Func <T, object> >[] navigationProperties) where T : class
        {
            IQueryable <T> query = db.GetQuery <T>(where, navigationProperties);

            return(query.ToList <T>());
        }
示例#6
0
        private T Get <T>(DbCtx db, Expression <Func <T, bool> > where, params Expression <Func <T, object> >[] navigationProperties) where T : class
        {
            IQueryable <T> query = db.GetQuery <T>(where, navigationProperties);

            return(query.FirstOrDefault());
        }
示例#7
0
        private IList <T> GetPaginated <T>(DbCtx db, int page, int limit, Expression <Func <T, bool> > where, params Expression <Func <T, object> >[] navigationProperties) where T : class
        {
            IQueryable <T> query = db.GetQuery <T>(where, navigationProperties);

            return(query.Skip(page * limit).Take(limit).ToList <T>());
        }