I receive a list of NHibernate entities that were retrieved by code that I cannot modify. I want to select a property from a child entity for each item in the list, but it is generating a new select for each item.
How can I get the sub-resources without changing the query that generated the entities passed in or changing the mapping (both of which would have an impact on unrelated code). Ideally, I wouldn't have to create a custom query at this layer of my code either.
Here is a sample. My entities:
public class Property {
public IList<Room> Rooms { get; set; }
}
public class Room {
public Template Template { get; set; }
}
public class Template {
public string Name { get; set; }
}
And the function I am calling:
public IEnumerable<string> GetTemplateNames(Property property) {
return property.Rooms.Select(room => room.Template.Name).Distinct();
}