nhibernate查询实现接口的所有对象 [英] nhibernate query all objects implementing an interface

查看:163
本文介绍了nhibernate查询实现接口的所有对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果你有一个苹果公司:一个什么,一个橙子公司,你想找到他们两个,因为他们是国王,你需要在NHibernate做什么?



完全依赖于HQL或条件查询,还是在映射中还有一些必须做的事情?如果有映射需求,可以用流利的NHibernatee来支持吗? 你可以做一个UnionSubClass映射。不幸的是它在Fluent中是不会被导入的。

你的映射可能类似于:

 < class name =IWhateverabstract =true> 
< id name =Id>
< / id>

< union-subclass name =Apple>
< property name =Blatype =int/>
< / union-subclass>

< property name =Blatype =int/>
< / union-subclass>
< / class>


For example, if you have an Apple : IWhatever, and an Orange : IWhatever and you want to find both of them because they are IWhatevers, what do you need to do in NHibernate?

Is it completely dependent on the HQL or criteria query, or is there something you must do in the mapping also? If there is a mapping requirement, can Fluent NHibernatee support it?

解决方案

You could do a UnionSubClass mapping. Unforntunately it is unsuported in Fluent.

You mapping would be something like:

<class name="IWhatever" abstract="true">
    <id name="Id">
    </id>

    <union-subclass name="Apple">
        <property name="Bla" type="int"/>
    </union-subclass>

    <union-subclass name="Orange">
        <property name="Bla" type="int"/>
    </union-subclass>
</class>

这篇关于nhibernate查询实现接口的所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆