使用NHibernate将本地SQL映射到Entity [英] Mapping native sql to Entity with NHibernate
本文介绍了使用NHibernate将本地SQL映射到Entity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用NHibernate将原始sql映射到实体?
Is possible to map a raw sql to an entity with NHibernate?
类似以下内容:
C#实体:
public virtual IList<Result> MyResult { get; set; }
Hbm.xml:
<bag name="MyResult">
<my-custom-sql type="Result">
SELECT * FROM ResultTable where MyComplexCondition = true
</my-custom-sql>
</bag>
结果具有自己的hbm.xml.可以做我想实现的目标吗?
Result has it own hbm.xml. Is possible to do what I want to achieve?
推荐答案
有一个称为 <subselect>
的功能.在这里查看更多
There is a feature, called <subselect>
. See more here
这可以应用于<class>
和<bag>
.这可能是如何在装有Languages
That could be applied on <class>
as well as on <bag>
. This could be the way how to use it on a bag for MyEntity
which has collection of Languages
<bag name="Languages" lazy="true" batch-size="25"
mutable="false" >
<subselect>
SELECT MyEntity_ID, Language_ID, IsNative FROM Languages
</subselect>
<key column="MyEntity_ID" />
<composite-element class="Language">
<parent name="MyEntity"/>
<many-to-one not-null="true" name="Language" class="Language" column="Language_ID" />
<property not-null="true" name="IsNative" column="IsNative"/>
</composite-element>
</bag>
这当然应该用于只读(不可变)解决方案
This of course, should be used for readonly (immutable) solutions
这篇关于使用NHibernate将本地SQL映射到Entity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文