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

天大地大妈咪最大 提交于 2019-12-21 04:14:11

问题


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.

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?


回答1:


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>


来源:https://stackoverflow.com/questions/2496915/fluent-nhibernate-named-query-without-using-hbm-file-for-the-map

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