Know the number of elements of a Iqueryable
c#, iqueryable, linq
Solution
Do you really need to return `IQueryable`? Returning `IQueryable` from your method doesn't provide much functionality since you can't access the members of an anonymous type without reflection. In this case I suggest that you create a concrete type in the query to be able to return `IQueryable<T>`:
class TaxIncrease
{
public int Tax { get; set; }
public int Increase { get; set; }
}
public IQueryable<TaxIncrease> listAll() {
ModelQMDataContext db = new ModelQMDataContext();
return from t in db.tax
select new TaxIncrease {Tax = t.tax1, Increase = t.increase};
}
and then you can do:
`listAll().Count();`
Problem
I have this Linq Query ``` public IQueryable listAll() { ModelQMDataContext db = new ModelQMDataContext(); IQueryable lTax = from t in db.tax select new {Tax = t.tax1, Increase = t.increase}; return lTax; } ``` how can I know the number of elements of lTax? Thanks.