Know the Number of Iqueryable Elements

I have this Linq request

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 to find out the number of lTax elements?

Thanks.

+4
source share
3 answers

Do you really need to return IQueryable ? Returning IQueryable from your method does not provide much functionality, since you cannot access elements of an anonymous type without reflection. In this case, I suggest you create a specific query type to be able to return an 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:

listAll().Count();

+6
source

lTax.Count () should do this ...

+2
source

declare lTax as List , so it can have .Count()

Then you can change this to Queryable, if you want, lTax.AsQueryable()

0
source

All Articles