nhibernate query all objects implementing an inter

2020-03-25 05:28发布

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?

2条回答
劫难
2楼-- · 2020-03-25 06:09

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>
查看更多
劳资没心,怎么记你
3楼-- · 2020-03-25 06:21

For Criteria, you don't need to map it. Just:

session.CreateCriteria<IWhatever>()
       .List<IWhatever>();

Keep in mind you'll only be able to query/sort/project on fields that exist in IWhatever.

查看更多
登录 后发表回答