views:

16

answers:

0

How can I eagerly fetch a collection, but just the N first items?

Using this code works, but is there an 'official way' to achieve that?

public Gallery GetById(int id)
{
    var session = GetSession();

    var criteria = session.CreateCriteria<Gallery>()
        .Add(Expression.Eq("Id", id))

        .SetFetchMode("Pictures", FetchMode.Eager)         
        .CreateAlias("Pictures", "p")

        .SetFirstResult(0)
        .SetMaxResults(24)
        ;

    return criteria.UniqueResult<Gallery>();
}

In this case, I'm bounding the results of Gallery, which is anyway unique result, but I want to bound the results of Pictures.