Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing Sql statements with Fluent NHibernate

Basically I want to be able to do this:

session.ExecuteSql("...");

I don't need it to map to any entities or return any values. Any suggestions?

like image 584
Micah Avatar asked May 12 '09 13:05

Micah


1 Answers

As already mentioned, this is not a Fluent NHibernate issue but here is an example:

public int GetSqlCount<T>(Session session, string table)
{
    var sql = String.Format("SELECT Count(*) FROM {0}", table);
    var query = session.CreateSQLQuery(sql);
    var result = query.UniqueResult();
    // Could also use this if only updating values:
    //query.ExecuteUpdate();

    return Convert.ToInt32(result);
}

You will want to investigate the ISQLQuery interface, depending on your needs.

like image 163
Steven Lyons Avatar answered Oct 19 '22 04:10

Steven Lyons