gpt4 book ai didi

nhibernate - CreateSqlQuery不会在NHibernate中检索标量值

转载 作者:行者123 更新时间:2023-12-03 12:06:11 26 4
gpt4 key购买 nike

为什么codigoUnificacion变量始终为null?

public int? GetCodigoUnificacionFamiliar(IList<Pariente> parientes)
{
List<string> cedulas = new List<string>();

parientes.ToList().ForEach(p => cedulas.Add(p.Cedula));

int? codigoUnificacion = Session
.CreateSQLQuery(@"SELECT DISTINCT
sa_bec_mtc_doc as Codigo
FROM sa_bec_matricula
INNER JOIN sa_matricula ON sa_bec_matricula.sa_mtc_num = sa_matricula.sa_mtc_num
INNER JOIN sa_alumno ON sa_matricula.sa_alu_cod = sa_alumno.sa_alu_cod
INNER JOIN sa_periodo ON sa_matricula.sa_per_cod = sa_periodo.sa_per_cod
INNER JOIN sa_tpo_beca ON sa_bec_matricula.sa_tpo_bec_cod = sa_tpo_beca.sa_tpo_bec_cod
WHERE sa_alu_ced IN (:cedulas)
AND sa_per_abi = 1
AND sa_tpo_bec_gpr = 2")
.SetParameterList("cedulas", cedulas)
.UniqueResult() as int?;

return codigoUnificacion;
}

最佳答案

在NHibernate中执行返回标量值的查询时

这将起作用!

var max = session.CreateSQLQuery(query).UniqueResult();
decimal s = max != null ? Decimal.Parse(max.ToString()) : -1;

这将返回null!
decimal? s = session.CreateSQLQuery(query).UniqueResult() as decimal?;

这将不编译

因为只接受引用或可为空的类型
decimal s = session.CreateSQLQuery(query).UniqueResult() as decimal;

类型转换异常

NHibernate引发异常
decimal s = (decimal)session.CreateSQLQuery(query).UniqueResult();

关于nhibernate - CreateSqlQuery不会在NHibernate中检索标量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4169973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com