NHibernate Projections to retrieve a Collection?
- by Simon Söderman
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!