Having entities:
public class Employee
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
.
. other properties
.
public virtual IList<Address> Addresses { get; set; }
}
public class Address
{
public virtual int Id { get; set; }
public virtual Employee Employee { get; set; }
public virtual string Value { get; set; }
.
. other properties
.
}
How can I retrieve a list of employees with populated Addresses lists, but
only retrieving certain properties for each entity type?
*For example let's say that for employees only Id and Name fields are
required, and for addresses only Id and Value.*
I know I could retrieve all the required fields from employees and
addresses separately:
var employees = session
.CreateCriteria<Employee>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("Id"), "Id")
.Add(Projections.Property("Name"), "Name"))
.SetResultTransformer(Transformers.AliasToBean(typeof(Employee)))
.List<Employee>();
var addresses = session
.CreateCriteria<Address>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("Id"), "Id")
.Add(Projections.Property("Value"), "Value")
.Add(Projections.Property("Employee"), "Employee"))
.SetResultTransformer(Transformers.AliasToBean(typeof(Address)))
.List<Address>();
and then populate the Addresses collection for each employee, but I'm
thinking there must be an easier way.
http://stackoverflow.com/questions/11755202/how-to-retrieve-partially-populated-entity-graph/11755271#11755271
Thanks for your help!
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/nhusers/-/x6G33XDrJXYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.