我曾经能够使用 MySQL 在 NHibernate 2.1 中将以下代码作为多查询运行
var total = new LeagueInfoQuery { Count = true, User = CurrentUser }.CreateCriteria(session).FutureValue<int>();
var leagues = new LeagueInfoQuery { User = CurrentUser, PageSize = pageSize, Page = page, SortBy = sortBy, SortAsc = sortAsc }.CreateCriteria(session).Future<LeagueInfo>();
var results = PaginationHelper.CreateCustomPage<LeagueInfo>(leagues, pageSize, page, total.Value);
例如 LeagueInfoQuery 只是一个可以创建标准 ICriteria 的自定义查询对象。
但是,自从升级到 NHibernate 3.0 后,我现在遇到了语法错误。异常消息如下。
{“执行多条件时出错:[SELECT count(*) as y0_ FROM
League
this_ WHERE this_.User = ?p0;\r\nSELECT this_.Id as y0_, this_.Name as y1_, min(f1_.Date) as y2_, max(f1_.Date) as y3_, count(distinct t2_.Id) as y4_ FROMLeague
this_ inner joinTeam
t2_ on this_.Id=t2_.League inner joinFixture
f1_ on this_.Id=f1_.League WHERE this_.User = ?p1 GROUP BY this_.Name ORDER BY y0_ desc limit ?p1;\r\n]"}
内部异常:
{“您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 ''b68d9d4e-a958-4fb8-8490-9e4401572f38'' 附近使用正确的语法”}
所以它看起来像一个语法错误,但这在 v2.1 中并没有发生,如果我在消息中编辑 SQL 以便参数是值,我可以让它工作。
那么为什么现在在 NHibernate 3.0 中会出现这个错误呢?我是否需要为 MySQL 语法配置一些特别的东西,如果需要怎么办?
干杯。