Nhibernate 获得;“命名查询不知道”;会话上出错。GetNamedQuery()
调用session.GetNamedQuery()时,我始终收到一个“命名查询未知”映射异常。我正在将Fluent与NHibernate 3.0一起使用,并且在一个hbm.xml文件中有查询。为了简单起见,我把所有东西都放在同一个组件中。我已经将xml文件的构建操作设置为“嵌入式资源” 我的配置如下所示:Nhibernate 获得;“命名查询不知道”;会话上出错。GetNamedQuery(),nhibernate,session,hbm,Nhibernate,Session,Hbm,调用session.GetNamedQuery()时,我始终收到一个“命名查询未知”映射异常。我正在将Fluent与NHibernate 3.0一起使用,并且在一个hbm.xml文件中有查询。为了简单起见,我把所有东西都放在同一个组件中。我已经将xml文件的构建操作设置为“嵌入式资源” 我的配置如下所示: var nhConfig = Fluently.Configure() .Database(SQLAnywhereConfiguration
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");
<?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>
var nhConfig=fluntly.Configure()
.数据库(SQLAnywhere)配置
.sqlanywhere 10
.ConnectionString(“uid='dba';pwd='sql';dsn=db”))
.ExposeConfiguration(c=>c.SetProperty(“当前会话上下文类”、“线程静态”))
.Mappings(m=>m.FluentMappings.AddFromAssemblyOf())
.BuildConfiguration();
var sessionFactory=nhConfig.BuildSessionFactory();
ISession session=sessionFactory.OpenSession();
CurrentSessionContext.Bind(会话);
NHibernate.IQuery q=session.GetNamedQuery(“GetFirstParty”);
我的GetFirstParty.hbm.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");
<?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>
我在这里错过了什么
请帮忙
谢谢
Mike您需要在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();
var nhConfig=fluntly.Configure()
.数据库(SQLAnywhere)配置
.sqlanywhere 10
.ConnectionString(“uid='dba';pwd='sql';dsn=db”))
.ExposeConfiguration(c=>c.SetProperty(Environment.CurrentSessionContextClass,“线程\静态”))
.Mappings(m=>
{
m、 FluentMappings.AddFromAssemblyOf();
m、 HbmMappings.AddFromAssemblyOf();
})
.BuildConfiguration();
就是这样。繁荣谢谢。你为什么不选择答案呢?