I like that solution; it looks like a handy little utility class.

There's now a TransformUsing() method on IQueryOver (r4980), so you can write:

Session.QueryOver<Tenant>()
   .Select(x => x.Id, x => x.FirstName, x => x.LastName)
.TransformUsing(new PartialObjectTransformer<Tenant>(x => x.Id, x => x.FirstName, x => x.LastName))
   .List<Tenant>()

I've also fixed the property aliasing to allow usage of the AliasToBean<T> transformer, so you could also write:

Tenant tenantDto = null;
Session.QueryOver<Tenant>()
   .Select(list => list
       .Select(t => t.Id).WithAlias(() => tenantDto.Id)
       .Select(t => t.FirstName).WithAlias(() => tenantDto.FirstName)
       .Select(t => t.LastName).WithAlias(() => tenantDto.LastName))
   .TransformUsing(Transforms.AliasToBean<Tenant>())
   .List<Tenant>()

(I updated the blog with an example here: http://nhforge.org/blogs/nhibernate/archive/2009/12/17/queryover-in-nh-3-0.aspx#Projections)

Finally, another option is to use the LINQ provider to generate the partial classes/DTOs. Something like this should work:

from t in s.Query<Tenant>()
select new Tenant
   {
       Id = t.Id,
       FirstName = t.FirstName,
       LastName = t.LastName,
   }



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