that's a nice feature of 3.0. I'm still running 2.1.2
with 2.1.2 you would project to the productdto and then project a list
of persondtos. you would then associate the people with the product
and use the result. 3.0 may be different.

On Sep 30, 6:20 pm, Vikram Nayak <[email protected]> wrote:
> Thanks!  I agree, intermingling Entities and DTO is not a good idea.
> But I don't want to flatten the Person Entity for a couple of reason,
> the Person entity is fairly light weight and there is a collection of
> Inventors , how do you flatten a list ?
>
> btw, I just found that NH3.0 does support Entity projects.
>
> On Sep 30, 1:28 pm, Jason Meckley <[email protected]> wrote:
>
> > 1st red flag I see is the relation between the productdto and the
> > person. I don't think they should intermingle.
> > NH can project to flat objects. if you flatten out the person object
> > on productdto you can then project from NH to the productdto. for
> > example
> > class productdto
> > {
> >    long ProductId {get;set;}
> >    long PersonId {get;set;}
> >    string Name {get;set;}}
>
> > something like
> > "select p.id as ProductId, i.id as PersonId, i.FirstName + " " +
> > i.LastName as Name from Product p join p.InventedBy i"
> > SetResultTransformer(Transformers.AliasToBean)
> > List<ProductDto>()
>
> > the other option is to use a framework like AutoMapper to convert the
> > domain into a dto. AutoMapper instead of NH projections.
>
> > On Sep 30, 2:08 pm, Vikram Nayak <[email protected]> wrote:
>
> > > Documentation on this is sparse, an many of the blog posts I read say
> > > Entity Projection is not supported in NHibernate. If it's not
> > > supported any suggestions on how to handle this.
>
> > > I have two simple entities (PRODUCT and PERSON) and a DTO
> > > (PRODUCTDTO). I am trying to project the Product.Id and
> > > Product.InventedBy properties from Product to the ProductDTO which
> > > will be used in a Report.
>
> > >         public class Product
> > >         {
> > >                 public virtual long Id { get; set; }
> > >                 public virtual string Name { get; set; }
> > >                 public virtual string Category { get; set; }
> > >                 public virtual bool Discontinued { get; set; }
> > >                 public virtual Person InventedBy { get; set; }
> > >         }
>
> > >         public class Person
> > >         {
> > >                 public virtual long Id { get; set; }
> > >                 public virtual string FirstName { get; set; }
> > >                 public virtual string LastName { get; set; }
> > >         }
>
> > >         public class ProductDto
> > >         {
> > >                 public long Id { get; set; }
> > >                 public Person InventedBy { get; set; }
> > >         }
>
> > >                         var product = new Product { Name = "Mac",
> > > Category = "Computers" };
> > >                         var person = new Person {FirstName = "Steve", 
> > > LastName = "J"};
> > >                         product.InventedBy = person;
> > >                         IProductRepository repository = new 
> > > ProductRepository();
> > >                         repository.Add(product);
>
> > >                        ICriteria criteria =
> > > session.CreateCriteria<Product>();
> > >                        criteria.SetProjection(Projections.Property("Id"));
> > >                        
> > > criteria.SetProjection(Projections.Property("InventedBy"));
>
> > > criteria.SetResultTransformer(Transformers.AliasToBean(typeof(ProductDto)));
> > >                         var list = criteria.List<ProductDto>();
> > >                         foreach (var dto in list)
> > >                         {
> > >                                 Console.WriteLine(dto.Id);    //ID is 
> > > currently populated
> > >                                 
> > > Console.WriteLine(dto.InventedBy.FirstName);  //InventedBy is not
> > >                         }

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