string HQL = "SELECT t.Mb_id ,t.FromID ,MAX(case when t.FromID!=0 then A.RealName else t.Realname end),MAX(t.MBMessage as string) from Author A left join A.MessageBoards t where t.Mb_id<:Mb_id group by t.Mb_id,t.FromID";
上面红色部分MBMessage在数据库中对应的字段的类型为ntext,会报标题所指的错误,按下面的代码修改后正常。
string HQL = "SELECT t.Mb_id ,t.FromID ,MAX(case when t.FromID!=0 then A.RealName else t.Realname end),MAX(cast(t.MBMessage as string)) from Author A left join A.MessageBoards t where t.Mb_id<:Mb_id group by t.Mb_id,t.FromID";