当我运行这些代码时出现以下错误,请帮我解决问题。
代码:
public LoanMaturityDate RetrieveChequeDetails(string acctNumber)
{
// string query = "select foracid, (SELECT NVL(MAX(lim_exp_date),gam.acct_opn_date) FROM LHT, LHET WHERE LHT.ACID = gam.acid AND LHT.DEL_FLG !='Y'AND LHT.ENTITY_CRE_FLG = 'Y' AND LHT.ACID = LHET.ACID AND LHT.SERIAL_NUM = LHET.SERIAL_NUM AND LHT.APPLICABLE_DATE <= '31-Dec-2012' AND LHET.LIM_INACTIVE_DATE > '31-Dec-2012'AND LHET.LCHG_TIME = ( SELECT MAX(ONE.LCHG_TIME) FROM LHET ONE WHERE ONE.ACID = LHT.ACID AND ONE.SERIAL_NUM = LHT.SERIAL_NUM)) from gam where foracid='000333010003520'and schm_type in ('LAA')";
string query = @"select foracid,
(SELECT NVL(MAX(lim_exp_date),gam.acct_opn_date)
FROM LHT, LHET
WHERE LHT.ACID = gam.acid
AND LHT.DEL_FLG !='Y'
AND LHT.ENTITY_CRE_FLG = 'Y'
AND LHT.ACID = LHET.ACID
AND LHT.SERIAL_NUM = LHET.SERIAL_NUM
AND LHT.APPLICABLE_DATE <= '31-Dec-2012'
AND LHET.LIM_INACTIVE_DATE > '31-Dec-2012'
AND LHET.LCHG_TIME = ( SELECT MAX(ONE.LCHG_TIME)
FROM LHET ONE
WHERE ONE.ACID = LHT.ACID
AND ONE.SERIAL_NUM = LHT.SERIAL_NUM)) exp_date
from gam where foracid='000333010003520'
and schm_type in ('LAA')
";
ISession session = BuildSession();
var result = session.CreateSQLQuery(query);//.AddEntity("exp_date", typeof(GAM));//session.CreateSQLQuery(query, "exp_date", typeof(LHT));
result.AddScalar("foracid", NHibernate.NHibernateUtil.String);
result.AddScalar("exp_date", NHibernate.NHibernateUtil.DateTime);
var res = result.SetResultTransformer(new NHibernate.Transform.AliasToBeanResultTransformer(typeof(LoanMaturityDate)));
return res as LoanMaturityDate;
}
public class LoanMaturityDate
{
[DataMember]
public virtual string foracid { get; set; }
[DataMember]`enter code here`
public virtual DateTime exp_date { get; set; }
}
错误:
ReturnAliases = &#39;((NHibernate.Impl.SqlQueryImpl)(结果))ReturnAliases&#39。扔了一个 类型&#39; System.NotSupportedException&#39;
的例外情况ReturnTypes =&#39;((NHibernate.Impl.SqlQueryImpl)(result))。ReturnTypes&#39; 抛出了#System; NoSupportedException&#39;
类型的例外
答案 0 :(得分:0)
要使AliasToBean起作用,返回的列必须与实体的属性名称完全匹配,并且属于同一类型。