NHibernate Projections to retrieve a Collection?

Posted by Simon Söderman on Stack Overflow See other posts from Stack Overflow or by Simon Söderman
Published on 2010-04-12T11:59:32Z Indexed on 2010/04/12 12:03 UTC
Read the original article Hit count: 337

Filed under:
|

I´m having some trouble retrieving a collection of strings in a projection: say that I have the following classes

public class WorkSet {
    public Guid Id { get; set; }
    public string Title { get; set; }
    public ISet<string> PartTitles { get; protected set; }
}
public class Work {
    public Guid Id { get; set; }
    public WorkSet WorkSet { get; set; }
    //a bunch of other properties
}

I then have a list of Work ids I want to retrieve WorkSet.Title, WorkSet.PartTitles and Id for.

My tought was to do something like this:

            var works = Session.CreateCriteria<Work>()
            .Add(Restrictions.In("Id", hitIds))
            .CreateAlias("WorkSet", "WorkSet")
            .SetProjection(
            Projections.ProjectionList()
                .Add(Projections.Id())
                .Add(Projections.Property("WorkSet.Title"))
                .Add(Projections.Property("WorkSet.PartTitles")))
            .List();

The Id and Title loads up just fine, but the PartTitles returns null. Suggestions please!

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about icriteria