public GenericSearchResult <CustomerReviewVote> SearchCustomerReviewVotes(CustomerReviewVoteSearchCriteria criteria) { if (criteria == null) { throw new ArgumentNullException($"{nameof(criteria)} must be set"); } var retVal = new GenericSearchResult <CustomerReviewVote>(); using (var repository = _repositoryFactory()) { var query = repository.CustomerReviewVotes; if (!criteria.CustomerReviewIds.IsNullOrEmpty()) { query = query.Where(x => criteria.CustomerReviewIds.Contains(x.CustomerReviewId)); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "CreatedDate", SortDirection = SortDirection.Descending } }; } query = query.OrderBySortInfos(sortInfos); retVal.TotalCount = query.Count(); var customerReviewVoteIds = query.Skip(criteria.Skip) .Take(criteria.Take) .Select(x => x.Id) .ToList(); retVal.Results = _customerReviewService.GetVoteByIds(customerReviewVoteIds.ToArray()) .OrderBy(x => customerReviewVoteIds.IndexOf(x.Id)).ToList(); return(retVal); } }