在SQLServer中有如下语句:
select MAX(ModuleCode) from Moduleinfo where ParentCode ='4'其中ModuleCode为nvarchar(64)在HQL中使用如下语句报错:SELECT MAX(ModuleCode) FROM ModuleInfo WHERE ParentCode=:ParentCode错误信息:
Can't extract the type of one parameter of a HQL function: expression->{ModuleCode}; check aliases. [SELECT MAX(ModuleCode) FROM OBS.Domain.ModuleInfo WHERE ParentCode=:ParentCode]ModuleCode在数据库中的值如下:4,401,40101等等
这个是由于ModuleCode为string类型造成的,但是在SQL Server中可以,为什么在HQL中不行呢?
还是语句写错了?
select MAX(ModuleCode) from Moduleinfo where ParentCode ='4'其中ModuleCode为nvarchar(64)在HQL中使用如下语句报错:SELECT MAX(ModuleCode) FROM ModuleInfo WHERE ParentCode=:ParentCode错误信息:
Can't extract the type of one parameter of a HQL function: expression->{ModuleCode}; check aliases. [SELECT MAX(ModuleCode) FROM OBS.Domain.ModuleInfo WHERE ParentCode=:ParentCode]ModuleCode在数据库中的值如下:4,401,40101等等
这个是由于ModuleCode为string类型造成的,但是在SQL Server中可以,为什么在HQL中不行呢?
还是语句写错了?
string where = " ParentCode=:ParentCode";
ModuleInfo obj = new ModuleInfo();
string hql = string.Format("SELECT MAX(ModuleCode)FROM ModuleInfo {0}",
where.ToUpper().StartsWith("WHERE") ? where : "WHERE " + where);IQuery query = Session.CreateSQLQuery(hql).SetString("ParentCode", strParentCode);
解决办法:CreateQuery改用CreateSQLQuery
但不知道这样写是不是与具体数据库相关?