尝试将存储过程映射到类。我可以使用此代码执行存储过程。
var list = NHibernateSessionManager.GetSession().CreateSQLQuery("call USREALCT.CELADRVINF(?)")
.SetString(0,driverID)
.UniqueResult();
return list;
但是当我尝试使用带有此代码的命名查询执行时,我会收到错误。
return NHibernateSessionManager.GetSession()
.GetNamedQuery("CELADRVINF")
.SetString(0,driverID)
.UniqueResult<Driver>();
这是我的班级。
public class Driver : DriverScorecard.Data.IDriver
{
public Driver()
{
}
public virtual string DriverID
{
get;
set;
}
public virtual string FirstName
{
get;
set;
}
public virtual string LastName
{
get;
set;
}
public virtual DateTime DOB
{
get;
set;
}
public virtual string PhoneHome
{
get;
set;
}
public virtual string PhoneCell
{
get;
set;
}
public virtual string AddressLine1
{
get;
set;
}
public virtual string AddressLine2
{
get;
set;
}
public virtual string AddressCity
{
get;
set;
}
public virtual string AddressState
{
get;
set;
}
public virtual string AddressZip
{
get;
set;
}
public virtual string SkinTheme
{
get;
set;
}
这是我的映射文件。
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DriverScorecard.Data" namespace="DriverScorecard.Data.Model">
<sql-query name='CELADRVINF'>
<return alias='Dri' class='Driver'>
<return-property name="FirstName" column="FNAMEO"/>
<return-property name="LastName" column="LNAMEO"/>
<return-property name="DOB" column="BDATEO"/>
<return-property name="Address1" column="ADDR1O"/>
<return-property name="Address2" column="ADDR2O"/>
<return-property name="AddressCity" column="CITYO"/>
<return-property name="AddressState" column="STATEO"/>
<return-property name="AddressZip" column="ZIPO"/>
<return-property name="PhoneHome" column="HOMEPHONEO"/>
<return-property name="PhoneCell" column="CELLPHONEO"/>
</return>
<![CDATA[call USREALCT.CELADRVINF('?')]]>
</sql-query>
</hibernate-mapping>
让我感到困惑。我错过了什么?
- config {NHibernate.Cfg.Configuration} NHibernate.Cfg.Configuration
+ ClassMappings Count = 0 System.Collections.Generic.ICollection<NHibernate.Mapping.PersistentClass> {System.Collections.Generic.Dictionary<string,NHibernate.Mapping.PersistentClass>.ValueCollection}
+ CollectionMappings Count = 0 System.Collections.Generic.ICollection<NHibernate.Mapping.Collection> {System.Collections.Generic.Dictionary<string,NHibernate.Mapping.Collection>.ValueCollection}
EntityNotFoundDelegate null NHibernate.Proxy.IEntityNotFoundDelegate
+ EventListeners {NHibernate.Event.EventListeners} NHibernate.Event.EventListeners
+ FilterDefinitions Count = 0 System.Collections.Generic.IDictionary<string,NHibernate.Engine.FilterDefinition> {System.Collections.Generic.Dictionary<string,NHibernate.Engine.FilterDefinition>}
+ Imports Count = 0 System.Collections.Generic.IDictionary<string,string> {System.Collections.Generic.Dictionary<string,string>}
+ Interceptor {NHibernate.EmptyInterceptor} NHibernate.IInterceptor {NHibernate.EmptyInterceptor}
+ NamedQueries Count = 0 System.Collections.Generic.IDictionary<string,NHibernate.Engine.NamedQueryDefinition> {System.Collections.Generic.Dictionary<string,NHibernate.Engine.NamedQueryDefinition>}
+ NamedSQLQueries Count = 0 System.Collections.Generic.IDictionary<string,NHibernate.Engine.NamedSQLQueryDefinition> {System.Collections.Generic.Dictionary<string,NHibernate.Engine.NamedSQLQueryDefinition>}
+ NamingStrategy {NHibernate.Cfg.DefaultNamingStrategy} NHibernate.Cfg.INamingStrategy {NHibernate.Cfg.DefaultNamingStrategy}
- Properties Count = 7 System.Collections.Generic.IDictionary<string,string> {System.Collections.Generic.Dictionary<string,string>}
+ [0] {[use_reflection_optimizer, True]} System.Collections.Generic.KeyValuePair<string,string>
+ [1] {[session_factory_name, db2400dialect]} System.Collections.Generic.KeyValuePair<string,string>
+ [2] {[connection.provider, NHibernate.Connection.DriverConnectionProvider]} System.Collections.Generic.KeyValuePair<string,string>
+ [5] {[generate_statistics, true]} System.Collections.Generic.KeyValuePair<string,string>
+ [6] {[show_sql, true]} System.Collections.Generic.KeyValuePair<string,string>
+ Raw View
+ SqlFunctions Count = 0 System.Collections.Generic.IDictionary<string,NHibernate.Dialect.Function.ISQLFunction> {System.Collections.Generic.Dictionary<string,NHibernate.Dialect.Function.ISQLFunction>}
+ SqlResultSetMappings Count = 0 System.Collections.Generic.IDictionary<string,NHibernate.Engine.ResultSetMappingDefinition> {System.Collections.Generic.Dictionary<string,NHibernate.Engine.ResultSetMappingDefinition>}
+ Static members
+ Non-Public members
10:23:40.950NHibernate 4.0.3.GA(程序集4.0.0.4000)
==========
在应用程序
配置文件中找不到10:23:41.043hibernate-configuration部分
==========
10:23:41.043Bytecode提供商名称:lcg
==========
10:23:41.059使用反射优化器
==========
10:23:44.487connection.provider = NHibernate.Connection.DriverConnectionProvider
==========
10:23:44.487dialect = NHibernate.Dialect.DB2400Dialect
==========
==========
10:23:44.487generate_statistics =真
==========
10:23:44.487show_sql =真
==========
10:23:44.487db2400dialect
==========
10:23:44.487在程序集中搜索映射文档:DriverScorecard.Data
==========
10:23:44.487Mapping资源:DriverScorecard.Data.CELADRVINF.hbm.xml
==========
10:23:45.516使用方言:NHibernate.Dialect.DB2400Dialect
==========
10:23:45.610Configured SessionFactory:db2400dialect
==========
10:23:45.610properties:
System.Collections.Generic.Dictionary`2 [System.String,System.String]