If I have two classes:
public class Foo
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Bar Bar { get; set; }
}
public class Bar
{
public virtual int Id { get; set; }
public virtual string Code { get; set; }
public virtual string Name { get; set; }
}
And I want to only return Foo.Id, Foo.Name and Bar.Code (ignoring
Bar.Id and Bar.Name) I was thinking that projections would be the way
to go:
IList<Foo> result = session.CreateCriteria(typeof(Foo))
.CreateAlias("Bar", "Bar")
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("Id"), "Id")
.Add(Projections.Property("Name"), "Name")
.Add(Projections.Property("Bar.Code"), "Bar.Code"))
.SetResultTransformer(Transformers.AliasToBean(typeof(Foo)))
.List<Foo>();
When I run this, however, the transformer complains of not being able
to find a setter for the property Bar.Code. I understand this is
because the projection cannot resolve the sub-property. I can't find
much of a reference on how to do this sort of query. Any thoughts?
Thanks,
Colin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
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
-~----------~----~----~----~------~----~------~--~---