NHibernate.NET for ORACLE 10g“无法执行查询”
这是我的密码 我想知道你想错了吗NHibernate.NET for ORACLE 10g“无法执行查询”,nhibernate,Nhibernate,这是我的密码 我想知道你想错了吗 public IList listdataserviceplan(String custid) { using (ISession session = NHibernateHelper.OpenSession()) { string query = ” select a.ServicePlanId as ServicePlanId , a.ServiceDetail
public IList listdataserviceplan(String custid)
{
using (ISession session = NHibernateHelper.OpenSession())
{
string query = ” select a.ServicePlanId as ServicePlanId ,
a.ServiceDetail as ServiceDetail,”
+ ” a.DateServiceFix as DateServiceFix ,a.DateService as DateService,”
+ ” a.CaseNotSupport as CaseNotSupport ,a.ServiceChangeName as ServiceChangeName,”
+ ” a.DateServiceNew as DateServiceNew ,a.MaterialChange as MaterialChange,”
+ ” a.ServiceGuarantee as ServiceGuarantee ,a.ServiceMaintenance as ServiceMaintenance,”
+ ” a.ServiceCharge as ServiceCharge”
+ ” from BicIsu.Core.Domain.ServicePlan as a”
+ ” where 1=1″
+ ” and a.CustId = ‘” + custid + “‘ ”
+ ” order by a.ServicePlanId”;
var cons = session.CreateQuery(query).List();
return cons;
}
}
我看不出有什么错误,但我敢打赌这与那些超级复杂的魔法字符串有关。尝试:
string query = @"select a.ServicePlanId,
a.ServiceDetail,
a.DateServiceFix,
a.DateService,
a.CaseNotSupport,
a.ServiceChangeName,
a.DateServiceNew,
a.MaterialChange,
a.ServiceGuarantee,
a.ServiceMaintenance,
a.ServiceCharge
from ServicePlan as a
where 1=1
and a.CustId = :custId
order by a.ServicePlanId";
var result = session.CreateQuery(query)
.SetParameter("custId", custid)
.List();
仅供参考,可能不是编写hql查询的最佳方式。为什么不使用StringBuilder类呢。 它将是这样的:
var hqlQuery= new StringBuilder();
hqlQuery.Append("select a from ClassA");
hqlQuery.AppendFormat("where a.Id={0}",idVal);
return session.List<ClassA>(hqlQuery.toString());
我知道这不是答案。但肯定会在代码方面帮助您
现在谈谈你的问题。您得到的错误是什么。该查询是否正在启动,或者您是否遇到异常?如果您在NHibernate外部手动运行该查询,该查询是否有效?