2

session.GetNamedQuery() を呼び出すと、一貫して「Named Query Not Known」という MappingException が発生します。私は NHibernate 3.0 で Fluent を使用しており、hbm.xml ファイルにクエリがあります。簡単にするために、すべてを同じアセンブリに入れています。xml ファイルの Build Action を「Embedded Resource」に設定しました。

私の構成は次のようになります。

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

Fluent 構成に 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 に答える