Exemplo n.º 1
0
 public virtual IList <T> Get <TKey>(Expression <Func <T, TKey> > orderBy, PagingInfo paging, bool sortAsc = true, params string[] relates)
 {
     return(Get(null, orderBy, paging, sortAsc, relates));
 }
Exemplo n.º 2
0
        public virtual IList <T> Get <TKey>(Expression <Func <T, bool> > query, Expression <Func <T, TKey> > orderBy, PagingInfo paging, bool sortAsc = true, params string[] relates)
        {
            int pageIndex = 1;

            int pageSize = 10;

            if (paging.PageIndex > 0)
            {
                pageIndex = paging.PageIndex;
            }

            if (paging.PageSize > 0 && paging.PageSize < 100)
            {
                pageSize = paging.PageSize;
            }

            using (DC db = OpenContext())
            {
                var q = db.Set <T>().AsQueryable();

                if (null != query)
                {
                    q = q.Where(query);
                }

                foreach (var relate in relates)
                {
                    db.Set <T>().Include(relate);
                }

                paging.TotalCount = q.Count();

                if (orderBy != null)
                {
                    if (sortAsc)
                    {
                        q = q.OrderBy(orderBy);
                    }
                    else
                    {
                        q = q.OrderByDescending(orderBy);
                    }
                }

                q = q.Skip(pageSize * (pageIndex - 1)).Take(pageSize);

                return(q.ToList());
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Select records from DB
 /// </summary>
 /// <typeparam name="TKey"></typeparam>
 /// <param name="orderBy"></param>
 /// <param name="paging"><see cref="PagingInfo"/></param>
 /// <returns>collection of the current type, <see cref="System.Collections.Generic.IList&lt;T&gt;"/></returns>
 /// <remarks>if "to" parameter was passed as 0, it will be defaulted to 100, you can replace it by
 /// a valued defined in the config, and another point of interest, if from > to, from will be
 /// reseted to 0</remarks>
 public virtual IList <T> Get <TKey>(Expression <Func <T, TKey> > orderBy, PagingInfo paging, bool sortAsc = true)
 {
     return(Get(null, orderBy, paging, sortAsc));
 }