This is a simple and straightforward method I put in my base repositories to retrieve the row count of the results from an nhibernate criteria query.
protected int GetResultsCount(ICriteria criteria)
{
criteria.SetProjection(Projections.RowCount());
var eventsCount = criteria.UniqueResult<int>();
return eventsCount;
}
Here is a quick general purpose nhibernate criteria call to retrieve a list of results where the id is in a list. It is written as a generic method that I placed in my base repository and can use it for all of my domain objects. So T resolves to the type of domain object you are retrieving.
public IEnumerable<T> Get(IEnumerable<IdType> ids)
{
var criteria = Session.CreateCriteria<T>()
.Add(Restrictions.In("Id", ids.ToArray()));
return criteria.List<T>();
}
The sql this generates is essentially:
select * from DomainObjectTable
where id in('id1', 'id2', ...)

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 