流畅的nhibernate命名查询,而不使用hbm文件的地图 [英] fluent nhibernate named-query without using hbm file for the map

查看:141
本文介绍了流畅的nhibernate命名查询,而不使用hbm文件的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个命名查询,并将其与其中一个地图一起使用,我现在将其定义为流畅的地图。

I am needing to create a named-query, and use it with one of the maps, that i currently have defined as a fluent map.

是否可以继续使用流畅的地图,并能够在代码中动态创建命名查询?或者,正在切换到hbm地图唯一的选项?

is it possible to continue using the fluent map, and be able to create the named-query dynamically in code? or, is switching to a hbm map the only option?

推荐答案

也许我在误读这个问题,但是你不必须完全切换到hbm映射。

Maybe I'm misreading the question, but you don't have to switch to hbm mapping completely.

您可以继续使用流畅的NHibernate映射类,并使用hbm作为命名查询。在您的配置中,您可以包括实体和hbms。

You could continue to use fluent NHibernate to map classes and use hbm for named queries only. In your configuration, you'd then include the entities and the hbms.

_sessionFactory = Fluently.Configure()
.Mappings(m =>
{
   m.FluentMappings.AddFromAssemblyOf<SomeEntityMap>();
   m.HbmMappings.AddFromAssemblyOf<SomeEntityMap>();
})
.BuildSessionFactory();

在您的namedQueries.hbm.xml中,您只需定义命名查询:

In your namedQueries.hbm.xml you then only define named queries:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<query name="Some.Query.Of.Yours">
<![CDATA[
          from SomeEntity e
          where  e.Property = :propertyValue
          ]]>
</query>
</hibernate-mapping>

这篇关于流畅的nhibernate命名查询,而不使用hbm文件的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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