mathew
mathew

Reputation: 185

Nhibernate syntax problem?

Well i am rather new to nhibrenate syntax and need desperately your help.

I have a table called Cookie with the following attributes:

Id(int) , Datetime(datetime), UniqueId (string) , IsTransaction(bool) 

All i want is to produce a list of the above table like this

Id     Datetime     UniqueId    IsTransaction
       25/8/2011    789              1
       23/8/2011    789              0
       22/8/2011    789              0
       20/8/2011    789              0
       20/8/2011    789              0
       20/8/2011    789              1
       19/8/2011    789              0
       18/8/2011    789              0
       25/8/2011    111              1
       24/8/2011    111              0
       23/8/2011    111              0
       20/8/2011    111              0
       17/8/2011    111              0
       15/8/2011    111              1
       13/8/2011    111              0
       12/8/2011    111              0
       11/8/2011    111              0
       10/8/2011    111              0

To be honest i find it difficult do write that query even in plain SQL :(

Any ideas??

Thanks!

Upvotes: 0

Views: 99

Answers (1)

Baz1nga
Baz1nga

Reputation: 15579

session.CreateQuery("from Cookie").List();

//optionally you can add the where condition like this

session.CreateQuery("from Cookie where IsTransaction=1").List();

Both the above code is in HQL or you can use SQL as follows:

session.CreateSQLQuery("select * from Cookie");

//optionally you can add the where condition like this

session.CreateSQLQuery("select * from Cookie where IsTransaction=1").List();

instead of the * you could give your column names too if you want to select only a few columns.. I dont know why your Id field is empty..

Upvotes: 1

Related Questions