我在使用Nhbernate中的位置參數時遇到問題。「?」附近的語法錯誤:Nhibernate生成的查詢
條件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, ?, ?)]
我能做些什麼來解決這個問題?
很高興知道我不是唯一一個誰經歷過這個。 –