Projection Reuse Component (NHibernate)

Can I reuse component mapping in a projection?

Here is the mapping for the Vendor object:

   <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 the report, I would like to get these providers in the data transfer object, but reuse the Address component (since there are many fields and some formatting utility).

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 the address into its own table?

Thanks!

+3
source share
1 answer

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>();
0
source

Source: https://habr.com/ru/post/1718580/


All Articles