public Task <PagedListDTO <OrderDTO> > GetOrders(BaseCriteriaDTO criteria) { //PageSize int pageSize = Convert.ToInt32(ConfigurationManager.AppSettings["pageSize"].ToString()); //filter (expression in DB) Expression <Func <Order, bool> > filterExpression = x => x.Id != "0"; //Azure cosmos db not support method toString, and we use the next Workarround int filterAmount = 0; int.TryParse(criteria.Filter, out filterAmount); if (!string.IsNullOrWhiteSpace(criteria.Filter)) { filterExpression = filterExpression.Join( x => (x.OrderCustomer != null && x.OrderCustomer.ContactName.ToUpper().Contains(criteria.Filter.ToUpper())) || x.ShipAdress.ToUpper().Contains(criteria.Filter.ToUpper()) || x.ShipCity.ToUpper().Contains(criteria.Filter.ToUpper()) || x.ShipCountry.ToUpper().Contains(criteria.Filter.ToUpper()) || x.ShipPostalCode.ToUpper().Contains(criteria.Filter.ToUpper()) || x.TotalAmount == filterAmount ); } //order by Expression <Func <Order, object> >[] orderByExpressions = this.GetOrderByExpressions_Orders(criteria.OrderBy); Tuple <List <Order>, int> q = repositoryOrders.GetAllAsync(criteria.PageNumber, pageSize, filterExpression, criteria.OrderAsc, orderByExpressions); //get total entities int totalItems = q.Item2; //parse to DTO List <OrderDTO> items = q.Item1.ToList().Select(m => new OrderDTO { Id = Convert.ToInt32(m.Id), Created_At = m.Created_At, //OrderCustomer = m.OrderCustomer, Details = m.OrdersDetails.Where(x => x != null).Select(a => new OrderDetailDTO { Id = Convert.ToInt32(a.OrderDetailId), OrderId = Convert.ToInt32(m.Id), Discount = a.Discount, ProductId = a.ProductId, ProductName = (a.ProductSold != null ? a.ProductSold.Name : ""), Quantity = a.Quantity }).ToList(), shipAdress = m.ShipAdress, shipCity = m.ShipCity, shipCountry = m.ShipCountry, shipPostalCode = m.ShipPostalCode, TotalAmount = m.TotalAmount }).ToList(); var res = new PagedListDTO <OrderDTO>(totalItems, pageSize, items, criteria.PageNumber); return(Task.FromResult(res)); }