C# 使用 Fluent NHibernate 执行 Sql 语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/852720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Executing Sql statements with Fluent NHibernate
提问by Micah
Basically I want to be able to do this:
基本上我希望能够做到这一点:
session.ExecuteSql("...");
session.ExecuteSql("...");
I don't need it to map to any entities or return any values. Any suggestions?
我不需要它映射到任何实体或返回任何值。有什么建议?
采纳答案by Steven Lyons
As already mentioned, this is not a Fluent NHibernate issue but here is an example:
如前所述,这不是 Fluent NHibernate 问题,但这里有一个示例:
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.
您将需要研究 ISQLQuery 接口,具体取决于您的需要。