Beispiel #1
0
 public int GetOrderDetailCount(OrderDetailSearchCondition condition)
 {
     var query = _orderdetailRepository.Table;
     try
     {
         if (condition.Ids != null && condition.Ids.Any())
         {
             query = query.Where(q => condition.Ids.Contains(q.Id));
         }
         return query.Count();
     }
     catch(Exception e)
     {
         _log.Error(e,"数据库操作出错");
         return -1;
     }
 }
Beispiel #2
0
        public IQueryable<OrderDetailEntity> GetOrderDetailsByCondition(OrderDetailSearchCondition condition)
        {
            var query = _orderdetailRepository.Table;
            try
            {
                if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
                if(condition.OrderBy.HasValue)
                {
                    switch (condition.OrderBy.Value)
                    {
                        case EnumOrderDetailSearchOrderBy.OrderById:
                            query = condition.IsDescending?query.OrderByDescending(q=>q.Id):query.OrderBy(q=>q.Id);
                            break;
                    }

                }
                else
                {
                    query = query.OrderBy(q=>q.Id);
                }

                if (condition.Page.HasValue && condition.PageCount.HasValue)
                {
                    query = query.Skip((condition.Page.Value - 1)*condition.PageCount.Value).Take(condition.PageCount.Value);
                }
                return query;
            }
            catch(Exception e)
            {
                _log.Error(e,"数据库操作出错");
                return null;
            }
        }