问题描述
我需要创建一个命名查询,并将其与其中一个地图一起使用,我现在将其定义为流畅的地图。
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文件的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!