I have a data call in a Linq to Entities powered data access layer that is designed to make paged calls.
In doing so, I need to select a subset of the data, say 50 r
It may be possible, but it probably won't be much faster because of the criteria you're using. Since you're searching for text within a column value, you cannot use an index and thus must do a table scan. You could do a single query to get all records and do the Count
and Skip/Take
in linq-to-objects:
var queryResult = DatabaseContext.Table
.Where(x => !x.IsDeleted)
.OrderBy(i => i.ID)
.Where(p => (
p.PropertyOne.ToLower().Contains(query) ||
p.PropertyTwo.ToLower().Contains(query)
))
.ToList();
int count = queryResult.Count(); // now this will be a linq-to-objects query
var returnData = queryResult
.Skip(start).Take((length))
.AsEnumerable();
but you'd have to try it to see if it would be any faster.