Ignore parameters when using ISQLQuery in NHibernate

狂风中的少年 提交于 2020-02-06 03:36:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!