如何使用 C# 中的映射属性定义 NHibernate sql 查询?

发布于 2024-09-18 22:42:19 字数 918 浏览 6 评论 0原文

因此,对于我们正在开发的项目,我们使用业务实体本身的映射属性来映射整个域模型。我有一个有效的 sql 查询映射,我想使用映射属性来定义它,但我不知道如何执行此操作。任何帮助表示赞赏。

这是需要翻译的 xml 映射:

<sql-query name="Query1">
<return class="My.Class, My.Assembly">
    <return-property name="Field1" column="Field1"/>
    <return-property name="Field2" column="Field2"/>
    <return-property name="Field3" column="Field3"/>
    <return-property name="Field4" column="Field4"/>
    <return-property name="Field5" column="Field5"/>
    <return-property name="Field6" column="Field6"/>
    <return-property name="Field7" column="Field7"/>
    <return-property name="Field8" column="Field8"/>
    <return-property name="Field9" column="Field9" />
</return>
select Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field9 from dbo.udf_CUSTOM (:Param1, :Param2, :Param3)
</sql-query>

So for a project that we are working on we have our entire domain model mapped using mapping-attributes on the business entities themselves. I have a working sql-query mapping that I would like to define using the mapping-attributes but I am not sure how to do this. Any help is appreciated.

Here is the xml mapping that needs to be translated:

<sql-query name="Query1">
<return class="My.Class, My.Assembly">
    <return-property name="Field1" column="Field1"/>
    <return-property name="Field2" column="Field2"/>
    <return-property name="Field3" column="Field3"/>
    <return-property name="Field4" column="Field4"/>
    <return-property name="Field5" column="Field5"/>
    <return-property name="Field6" column="Field6"/>
    <return-property name="Field7" column="Field7"/>
    <return-property name="Field8" column="Field8"/>
    <return-property name="Field9" column="Field9" />
</return>
select Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field9 from dbo.udf_CUSTOM (:Param1, :Param2, :Param3)
</sql-query>

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

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

发布评论

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

评论(1

梦醒时光 2024-09-25 22:42:19

nHibernate 映射属性不支持它。如果确实需要使用外部 XML 映射,则可以定义它们。

请考虑Fluent nhibernate。这是映射对象的更好方法。

It's not supported by nHibernate mapping attributes. You can define an external XML mapping if you really need to use them.

Please consider fluent nhibernate. It's an even better way to map your objects.

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