private void ApplyQuery <TVal>(ref IQueryable <TVal> data, RepositoryQuery <TVal> query, out int totalCount) where TVal : class { if (query.Lookups.Any() || query.LookupsStr.Any()) { foreach (var lookup in query.Lookups) { data = data.Include(lookup); } foreach (var lookup in query.LookupsStr) { data = data.Include(lookup); } } if (query.Orders.Any()) { var next = false; foreach (var order in query.Orders) { var orderKey = (next ? "ThenBy" : "OrderBy") + (order.IsDesc ? "Descending" : ""); data = ApplyOrder(data, order.Property, orderKey); next = true; } } else { data = ApplyOrder(data, "Id", "OrderBy"); } if (query.Criteria != null && query.Criteria.Any()) { foreach (var expr in query.Criteria) { data = data.Where(expr); } } totalCount = data.Count(); if (query.SkipRows.HasValue) { data = data.Skip(query.SkipRows.Value); } if (query.TakeRows.HasValue) { data = data.Take(query.TakeRows.Value); } }
private IList <TVal> GetInternal <TVal>(IQueryable <TVal> data, RepositoryQuery <TVal> query, out int totalCount) where TVal : class { ApplyQuery(ref data, query, out totalCount); var result = data.ToList(); if (query.Loads.Any()) { foreach (var val in result) { foreach (var load in query.Loads) { Context.Entry(val).Collection(load).Load(); } } } return(result); }