【发布时间】:2010-12-01 13:42:09
【问题描述】:
是否可以在投影中重用组件映射?
这是 Vendor 实体的映射:
<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>
对于报告,我想在数据传输对象中检索这些供应商,但重用地址组件(因为有很多字段和一些有用的格式化行为)。
public class VendorDTO
{
public string Name;
public Address Address;
}
public class Address
{
public string Street;
public string City;
public string SomeUsefulBehavour();
}
如果不将 Address 拆分到它自己的表中,这是否可能?
谢谢!
【问题讨论】:
-
您要查询吗? “在投影中重用组件映射”是什么意思?我不明白这个问题...
-
可能的提示 - 您可以编写自己的 ResultTranslators;您可以尝试使用 HQL 构造 new Address();我没有尝试过,所以只是提示。
-
是的,我希望查询类似于:select new VendorDTO(vendor.Name, vendor.Address) from Vendor vendor 感谢您的提示。
-
选择新的 VendorDTO(vendor.Name, vendor.Address) 不起作用?
-
我认为您应该能够使用 AliasToBeanResultTransformer 实现这一目标
标签: nhibernate components dto projection