Reputation: 1037
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?
Upvotes: 5
Views: 10085
Reputation: 32428
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);
Upvotes: 17