Executing Sql statements with Fluent NHibernate

后端 未结 1 1997
情话喂你
情话喂你 2021-02-04 03:51

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?

1条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 04:29

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

    public int GetSqlCount(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.

    0 讨论(0)
提交回复
热议问题