在 Nhbernate 中使用位置参数时遇到问题。
Criteria GroupProperty 发出带有命名变量和位置变量的 sql。
这个说法:
session.CreateCriteria(typeof(MatchStageFrom))
.SetProjection(Projections.GroupProperty(
Projections.SqlFunction("substring", NHibernateUtil.String, Projections.Property("LastName"), Projections.Constant(0), Projections.Constant(1))
)
);
正在生成此 SQL:
SELECT substring(this_.LAST_NAME, @p0, @p1) as y0_ FROM MATCH_STAGING_FROM this_ GROUP BY substring(this_.LAST_NAME, ?, ?)
这会导致 SQL 出错:
Incorrect syntax near '?'.
could not execute query
[ SELECT substring(this_.LAST_NAME, @p0, @p1) as y0_ FROM MATCH_STAGING_FROM this_ GROUP BY substring(this_.LAST_NAME, ?, ?) ]
Positional parameters: #0>0 #1>1 #2>0 #3>1
[SQL: SELECT substring(this_.LAST_NAME, @p0, @p1) as y0_ FROM MATCH_STAGING_FROM this_ GROUP BY substring(this_.LAST_NAME, ?, ?)]
我能做些什么来修复它?