4

I am using an older version of nHibernate due to my old version of .net. QueryOver isn't an option. What's an efficient way to count the rows of a table with nhibernate?

1
  • I've tried something like this: int count = (int)s.CreateQuery("select count(*) from tablename").UniqueResult(); But it will only return the number of tables not the number of rows in that specific table. Commented Apr 29, 2013 at 15:11

1 Answer 1

7

The HQL you show in your comment is correct:

int count = (int)s.CreateQuery("select count(*) from [classname]").UniqueResult();

This will return the number of rows in the table represented by classname.

Sign up to request clarification or add additional context in comments.

1 Comment

s.CreateSQLQuery("select count(*) from [classname]") .UniqueResult<Int32>(); this one did it. I don't know why the other one wouldn't work. Thank you anyways.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.