I'd like to avoid the DTOs if possible.  Are there any examples of
extending the AliasToBean transformer to deal with situations like
this?

On Aug 12, 6:37 pm, armin-landscheidt <[email protected]> wrote:
> Try to use a third class:
>
> class FooBar{
>     public long Id{get;set;}
>     public string Name{get;set;}
>     public string BarCode{get;set;}
>
> }
>
>    IList<FooBar> 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"), "BarCode"))
>         .SetResultTransformer(Transformers.AliasToBean(typeof(FooBar)))
>         .List<FooBar>();
>
> This is for creating DTOs.
>
>
>
> > 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- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to