From NHibernate Sessions to Repository<T>
Before:
using (ISession session = _sessionManager.OpenSession())
{
IList list = session.CreateCriteria(typeof (State))
.SetFirstResult(Settings.Default.LogsPageSize*currentPage)
.SetMaxResults(Settings.Default.LogsPageSize)
.Add(Expression.Eq("Connection.Id", interfaceId))
.AddOrder(new Order("ArrivedAt", false))
.List();
return Util.ToArray<FileState>(list);
}
After:
return Repository<FileState>.FindAll(
Settings.Default.LogsPageSize*currentPage,
Settings.Default.LogsPageSize,
Order.Asc("ArrivedAt"),
Where.FileState.Connection.IdIs(interfaceId)
);
Update: Changed new Order() to use clearer factory method.
Comments
Comment preview