Default implementation of ResultTransformer are for some easy and normal
cases.If you need something special you should implement your own
ResultTrasformer (more easy to do than explain it).

2009/8/13 Colin Bowern <[email protected]>

>
> The actual object (not the example) has a rather large data set that
> is used during most processing.  I am looking to retrieve a subset of
> the properties for some bulk operations.  The SQL generated by the
> call is correct - the problem resides in mapping the results back to
> the entity.  The AliasToBean class does not understand how to deal
> with an element from a complex property like a class or struct.  If I
> can extend the behavior of the AliasToBean process to look for "." and
> navigate the sub-properties accordingly it would be sufficient.
>
> Cheers,
> Colin
>
> On Aug 13, 12:45 am, Fabio Maulo <[email protected]> wrote:
> > You want something that is not an entity. What you want ? an entity or
> > something else ?
> >
> > 2009/8/12 Colin Bowern <[email protected]>
> >
> >
> >
> >
> >
> >
> >
> > > 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 -
> >
> > --
> > Fabio Maulo- Hide quoted text -
> >
> > - Show quoted text -
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
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