How would I use Linq-To-Nhibernate (NH3.2) to have the database return to me the record count of a query without the records themselves?

StackOverflow https://stackoverflow.com/questions/9283997

Question

I have a bunch of queries to run, and if any of them return even a single result, I toggle a boolean variable true. If they all return no results, then it stays false.

Right now I'm just picking the smallest column and .Select() ing it, and then counting the results locally. But is there a way to have the database send back a single integer representing the record count of the query through linq-to-nhibernate?

Thanks!

Was it helpful?

Solution

Using the Query API, it would be

return Session.QueryOver<YourType>().RowCount();

or for Int64 (bigint)

return Session.QueryOver<YourType>().RowCountInt64();

If you're sending multiple queries, then you could use futures to batch all the queries together.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top