views:

197

answers:

1

How to convert the following hql to Criteria API

var criteria = this.Session.CreateQuery("select m, m.Attachments.size from AdvanceMessage m");

? Thanks

A: 

Your question is a little bit vague but it's something like this :

IList<AdvanceMessage> list = session.CreateCriteria(typeof(AdvanceMessage))
    .List<AdvanceMessage>();
Kris-I
This return only all fields from AdvanceMessages table. But the first one, I asked, generate a T-SQL statement like: SELECT m.*, COUNT(SELECTf.Id FROM MessageAttachment f WHERE f.messageId = m.messageId) FROM AdvanceMessages mI found a solution which is to create a criteria type of AdvanceMessage and add GroupProperty projection for this class fields and also to add an additional subquery projection with a RowNumber Projection inside.
isuruceanu