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.
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();
lTax.Count() should do it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With