3

Is it possible to reuse a component mapping in a projection?

Here is the mapping for the Vendor entity:

   <class name="Vendor" table="vendor">
     ...
     <property name="Name" column="Name" />
     <component name="Address" class="MyProject.Address, MyAssembly" >
       <property name="Street" column="street" />
       <property name="City" column="City" />
     </component>
   </class>

For a report I'd like to retrieve these vendors in a data transfer object but reuse the Address component (because there are many fields and some useful formatting behavour).

public class VendorDTO
{
    public string Name;
    public Address Address;

}

public class Address
{
    public string Street;
    public string City;
    public string SomeUsefulBehavour();
}

Is this possible without splitting Address out into it's own table?

Thanks!

Brian Low
  • 11,605
  • 4
  • 58
  • 63

1 Answers1

0

I believe this should 'just work':

Session.QueryOver<Vendor>()
    .SelectList(builder =>
        builder.Select(x => x.Name)
            .Select(x => x.Address))
    .TransformUsing(Transformers.AliasToBean<VendorDTO>())
    .List<VendorDTO>();
cbp
  • 25,252
  • 29
  • 125
  • 205