我在调用 session.GetNamedQuery() 时始终收到“命名查询未知”MappingException。我在 NHibernate 3.0 中使用 Fluent,并且在 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>
我在这里错过了什么???
请帮忙。
谢谢,
迈克
最佳答案
您需要在您的流畅配置中包含 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();
关于nhibernate - 在 session.GetNamedQuery() 上获取 "Named Query Not Know"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5116617/