简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM