i have a linq query similar like below.
IEnumerable<DataRow> query= (from item in IItemsTable.AsEnumerable()
where somecondition
select item);
how to check query contains any row or is empty?
You can use the extension method Any()
:
if(query.Any())
{
//query has results.
}
Note that if you only care whether there are rows or not (and don't subsequently do something with those rows) you can use another overload of Any()
to do it in one line:
bool queryhasresults = IItemsTable.AsEnumerable().Any(item => somecondition);
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