问题
I have to execute a native sql statement with NHibernate to the database. For this, i use:
var query = session.CreateSQLQuery(sql);
query.ExecuteUpdate();
Now, the sql contains the character : in a Column-Alias (which I need on this way) and NHibernate is handling this with a parameter. I haven't any parameter in this sql statement. Can I define somewhere, that NHibernate should not manage parameters for this ISQLQuery?
回答1:
Just use native connection for native SQL execution:
var cmd = session.Connection.CreateCommand(); // session is a NHibernate session
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
来源:https://stackoverflow.com/questions/25295351/ignore-parameters-when-using-isqlquery-in-nhibernate