2

调用 session.GetNamedQuery() 时,我始终收到“未知的命名查询”MappingException。我正在使用 Fluent 和 NHibernate 3.0,并且我在 hbm.xml 文件中有查询。为简单起见,我将所有东西都放在同一个程序集中。我已将 xml 文件上的构建操作设置为“嵌入式资源”。

我的配置如下所示:

var nhConfig = Fluently.Configure()
                    .Database(SQLAnywhereConfiguration
                  .SQLAnywhere10
                  .ConnectionString("uid='dba'; pwd='sql'; dsn=db"))
                  .ExposeConfiguration(c => c.SetProperty("current_session_context_class", "thread_static"))
                  .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Party>())
                  .BuildConfiguration();

            var sessionFactory = nhConfig.BuildSessionFactory();


            ISession session = sessionFactory.OpenSession();
            CurrentSessionContext.Bind(session);


            NHibernate.IQuery q = session.GetNamedQuery("GetFirstParty");

我的 GetFirstParty.hbm.xml 文件如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

  <query name="GetFirstParty">
    <![CDATA[from Party p where p.CaseNumber = :CaseNumber]]>
  </query>

</hibernate-mapping>

我在这里想念什么???

请帮忙。

谢谢,

麦克风

4

1 回答 1

8

您需要在流利的配置中包含 HBM 映射:

var nhConfig = Fluently.Configure()
                  .Database(SQLAnywhereConfiguration
                  .SQLAnywhere10
                  .ConnectionString("uid='dba'; pwd='sql'; dsn=db"))
                  .ExposeConfiguration(c => c.SetProperty(Environment.CurrentSessionContextClass, "thread_static"))
                  .Mappings(m => 
                  {
                    m.FluentMappings.AddFromAssemblyOf<Party>();
                    m.HbmMappings.AddFromAssemblyOf<Party>();
                  })
                  .BuildConfiguration();
于 2011-02-25T12:28:16.110 回答