How to write the following SQL query in NHibernate -


hey - i'm battling figure out how write following using nhibernate icriteria (multi criteria?) following:

(it's query list of first names ordered popularity in table in last day)

select firstname,count(firstname) occurances registrants timestamp between dateadd(day,-1, getdate()) , getdate() group firstname order count(firstname) desc  

also, given couple of columns table, excluding id, , nhibernate needs id's it's objects, what's easiest way "fake" id can results?

you need use projections , transformer this. here's background info http://nhibernate.info/doc/nh/en/index.html#querycriteria-projection

var criteria = session.createcriteria<registrant>()    .add(restrictions.between("timestamp", datetime.now.adddays(-1), datetime.now)    .addorder(order.desc(projections.count("firstname")))    .setprojection(projections.projectionlist()         .add(projections.groupproperty("firstname"), "firstname")         .add(projections.count("firstname"), "occurances")    .setresulttransformer(transformers.aliastobean<firstnameoccurance>());  criteria.list<firstnameoccurance>(); 

you'll need create class called firstnameoccurance has 2 properties called firstname , occurances.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -