Reputation: 331
using the folowing extention methods :
public static void SetParameters(this IQuery query, List<object> Parameters) {
for (int i = 0; i < Parameters.Count(); i++) {
query.SetParameter(i, Parameters[i]);
}
}
public static IQuery SetQuery(this ISession session, string Query, object[] Parameters) {
return session.CreateSQLQuery(Query + string.Empty + "(" + ParseExt(Parameters) + ")");
}
private static string ParseExt(object[] Parameters) {
var str = new List<string>();
for (int i = 0; i < Parameters.Length; i++) {
str.Add(":" + i);
}
return string.Join(",", str);
}
i'm creating a query :
public IEnumerable<T> Execute<T>(string Query, params dynamic[] Parameters) {
using (var _session = _transactionManager.GetSession()) {
var _cmd = _session.SetQuery(Query, Parameters);
if (Parameters != null) {
_cmd.SetParameters(Parameters.ToList());
}
return _cmd.List<T>();
}
}
throws the following error :
Remember that ordinal parameters are 1-based!
NOTE : i tried to change the index to start from 1
Upvotes: 4
Views: 1077
Reputation: 123861
The symbol for position-parameter is not :xxx
but ?
.
This change will work
private static string ParseExt(object[] Parameters) {
var str = new List<string>();
for (int i = 0; i < Parameters.Length; i++) {
//str.Add(":" + i);
str.Add("?"); // + i);
}
return string.Join(",", str);
}
Upvotes: 2