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

后端 未结 1 1425
眼角桃花
眼角桃花 2021-02-15 18:14

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, a

相关标签:
1条回答
  • 2021-02-15 18:31

    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>
    
    0 讨论(0)
提交回复
热议问题