当我使用Hibernate时,我收到错误"Incorrect syntax near '?'"
。
我的代码如下:
criteria.Add(Restrictions.InG("OrgUnit", orgUnits));
criteria.SetProjection(
Projections.ProjectionList()
.Add(Projections.GroupProperty("OrgUnit"), "OrgUnit")
.Add(Projections.GroupProperty("IncidentStatus"), "IncidentStatus")
.Add(Projections.SqlGroupProjection(
"Year(IncidentDate) as Year",
"Year(IncidentDate)",
new[] { "Year" },
new[] { NHibernateUtil.Int32 }))
.Add(Projections.SqlGroupProjection(
"Month(IncidentDate) as Month",
"Month(IncidentDate)",
new[] { "Month" },
new[] { NHibernateUtil.Int32 }))
.Add(
Projections.Count(
Projections.Conditional(
Restrictions.Where<SheIncidentEvent>(f => f.IsReportable == true),
Projections.Constant(1),
Projections.Constant(0))),
"TotalReportable")
.Add(
Projections.Sum(
Projections.Conditional(
Restrictions.Where<SheIncidentEvent>(f => f.IsReportable == true),
Projections.Constant(1),
Projections.Constant(0))),
"RiddorReportable")
.Add(
Projections.Sum(
Projections.Conditional(
Restrictions.Where<SheIncidentEvent>(f => f.IsLostTime == true),
Projections.Constant(1),
Projections.Constant(0))),
"LostTime")
.Add(Projections.Sum("LostTimeActual"), "TotalDaysLost")
.Add(
Projections.Sum(
Projections.Conditional(
Restrictions.Where<SheIncidentEvent>(f => f.IsNearMiss == true),
Projections.Constant(1),
Projections.Constant(0))),
"NearMiss"))
.SetResultTransformer(Transformers.AliasToBean(typeof(SheIncidentEventBreakdownByDateCounter)));
这会产生以下异常:
[ SELECT this_1_.SheOrgUnit_Id as y0_, this_.IncidentStatus_id as y1_, Year(IncidentDate) as Year, Month(IncidentDate) as Month, count((case when this_.IsReportable = ? then ? else ? end)) as y4_, sum((case when this_.IsReportable = @p0 then @p1 else @p2 end)) as y5_, sum((case when this_.IsLostTime = @p3 then @p4 else @p5 end)) as y6_, sum(this_.LostTimeActual) as y7_, sum((case when this_.IsNearMiss = @p6 then @p7 else @p8 end)) as y8_ FROM tblSheIncidentEvent this_ inner join tblSheModule this_1_ on this_.SheModule_id=this_1_.Id WHERE this_1_.SheCustomer_id = @p9 and this_1_.IsArchive = @p10 and this_1_.IsActive = @p11 and this_1_.SheOrgUnit_Id in (@p12) GROUP BY this_1_.SheOrgUnit_Id, this_.IncidentStatus_id, Year(IncidentDate), Month(IncidentDate) ]
Name:cp0 - Value:True Name:cp1 - Value:1 Name:cp2 - Value:0 Name:cp3 - Value:True Name:cp4 - Value:1 Name:cp5 - Value:0 Name:cp6 - Value:True Name:cp7 - Value:1 Name:cp8 - Value:0 Name:cp9 - Value:True Name:cp10 - Value:1 Name:cp11 - Value:0 Name:cp12 - Value:SheAzure.Model.Core.SheCustomer Name:cp13 - Value:False Name:cp14 - Value:True Name:cp15 - Value:SheAzure.Model.Core.SheOrgUnit
[SQL: SELECT this_1_.SheOrgUnit_Id as y0_, this_.IncidentStatus_id as y1_, Year(IncidentDate) as Year, Month(IncidentDate) as Month, count((case when this_.IsReportable = ? then ? else ? end)) as y4_, sum((case when this_.IsReportable = @p0 then @p1 else @p2 end)) as y5_, sum((case when this_.IsLostTime = @p3 then @p4 else @p5 end)) as y6_, sum(this_.LostTimeActual) as y7_, sum((case when this_.IsNearMiss = @p6 then @p7 else @p8 end)) as y8_ FROM tblSheIncidentEvent this_ inner join tblSheModule this_1_ on this_.SheModule_id=this_1_.Id WHERE this_1_.SheCustomer_id = @p9 and this_1_.IsArchive = @p10 and this_1_.IsActive = @p11 and this_1_.SheOrgUnit_Id in (@p12) GROUP BY this_1_.SheOrgUnit_Id, this_.IncidentStatus_id, Year(IncidentDate), Month(IncidentDate)]
任何人都可以解释这是什么问题,以及如何解决它?