执行SQL语句与功能NHibernate [英] Executing Sql statements with Fluent NHibernate

查看:174
本文介绍了执行SQL语句与功能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?

推荐答案

正如前面提到的,这是不是流利NHibernate的问题,但这里有一个例子:

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);
}

您将要调查ISQLQuery界面,根据您的需要。

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

这篇关于执行SQL语句与功能NHibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆