Search code examples
c#sqlnhibernateisqlquery

Ignore parameters when using ISQLQuery in NHibernate


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?


Solution

  • Just use native connection for native SQL execution:

    var cmd = session.Connection.CreateCommand(); // session is a NHibernate session
    cmd.CommandText = sql;
    cmd.ExecuteNonQuery();