在投影中重用组件(NHibernate)

发布于 2024-08-05 19:12:31 字数 725 浏览 1 评论 0原文

是否可以在投影中重用组件映射?

以下是供应商实体的映射:

   <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();
}

如果不将地址拆分到它自己的表中,这可能吗?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅气尐潴 2024-08-12 19:12:31

我相信这应该“有效”:

Session.QueryOver<Vendor>()
    .SelectList(builder =>
        builder.Select(x => x.Name)
            .Select(x => x.Address))
    .TransformUsing(Transformers.AliasToBean<VendorDTO>())
    .List<VendorDTO>();

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>();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文