fluent nhibernate named-query without using hbm file for the map

蓝咒 提交于 2019-12-03 12:50:15

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

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();

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!