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

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!

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top