0

In the NHiberante, I have this statement

 (from p in Session.Query<MyObject>() select p).Count(); 

is this equal to this ?

select count(*) from MyObject

assume object name is same as table name .

If the table data is huge, do we have a way to improve performance ?

thanks

Gerard
  • 2,461
  • 2
  • 26
  • 34
user595234
  • 6,007
  • 25
  • 77
  • 101
  • If the table is really large, one way to improve performance would be to cache results or store a running total somewhere. Not much you can do to improve a rowcount as it is. – dotjoe May 04 '12 at 14:04

1 Answers1

1

You can better use:

(from p in Session.Query<MyObject>() select p).LongCount();

SQLite query is:

select cast(count(*) as BIGINT) as col_0_0_ from MyObject myobject0_

You can create DBMS specific optimized queries with:

Session.CreateSQLQuery("sql query");

Questions about count optimizations:

optimize mysql count query

Community
  • 1
  • 1
Gerard
  • 2,461
  • 2
  • 26
  • 34