Conditionally adding .Take()
c#-4.0, linq
Solution
Add "AsQueryable" to make the types line up:
var orderQuery = subsetTable.Where(pred).OrderByDescending(o => o.CreationDate).AsQueryable();
if (condition)
orderQuery = orderQuery.Take(500);
Problem
Currently I have this that automatically takes 500 rows: ``` var orderQuery = subsetTable.Where(pred).OrderByDescending(o => o.CreationDate).Take(500); ``` I'd like to make the Take() conditional, something like this: ``` var orderQuery = subsetTable.Where(pred).OrderByDescending(o => o.CreationDate); if (condition) orderQuery = orderQuery.Take(500); ``` Is this possible? Edit: The compiler says "Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IOrderedQueryable'."