public static int CountHistoryByQuery(HistoryQuery query)
        {
            using (var context = new XiaoluEntities())
            {
                var repository = new HistoryRepository(context);

                int count = repository.GetPageCount(item => _isMatch(item, query));
                return count;
            }
        }
 private static dynamic _orderByKey(History obj, HistoryQuery query)
 {
     if (string.IsNullOrEmpty(query.OrderByKey))
         return obj.Id;
     return obj.GetType().GetProperty(query.OrderByKey).GetValue(obj);
 }
        public static List<History> GetHistoryListByQuery(HistoryQuery query)
        {
            using (var context = new XiaoluEntities())
            {
                var repository = new HistoryRepository(context);

                List<History> historys = repository.GetPageList(item => _isMatch(item, query), item => _orderByKey(item, query), query.OrderByValue, query.Offset, query.Limit);
                return historys;
            }
        }
        public static bool _isMatch(History obj, HistoryQuery query)
        {
            if (!string.IsNullOrEmpty(query.IdEqual) && !string.Equals(obj.Id, query.IdEqual))
                return false;
            if (!string.IsNullOrEmpty(query.IdNotEqual) && string.Equals(obj.Id, query.IdNotEqual))
                return false;

            if (!string.IsNullOrEmpty(query.UserIdEqual) && !string.Equals(obj.UserId, query.UserIdEqual))
                return false;
            if (!string.IsNullOrEmpty(query.ContentLike) && !obj.Content.Contains(query.ContentLike))
                return false;

            if ((null != query.MinCreationDate) && (obj.CreationDate < query.MinCreationDate))
                return false;
            if ((null != query.MaxCreationDate) && (obj.CreationDate > query.MaxCreationDate))
                return false;

            return true;
        }
 public static History GetHistoryById(string id4query)
 {
     HistoryQuery query = new HistoryQuery() { IdEqual = id4query };
     History historyInDb = GetHistoryListByQuery(query).FirstOrDefault();
     return historyInDb;
 }