这一章我们主要介绍一下 IbatisNet 里面的其它用法主要有以下几点:
1,如何得到运行时 ibatis.net 动态生成的 SQL 语句?
2,如何获取 DbCommand?
3,如何返回 DataTable,DataSet?
4,批量数据的插入
……
首先看一下获取的
sql 语句的方法:
代码
IMappedStatement statement = sqlMapper.GetMappedStatement(statementName);
获 取
MappedStatement 对象
sqlMap.LocalSession 获取 ISqlMapSession
RequestScope 代 表 一 个 请 求 范 围 内 所 有 的 处 理 数 据 , 例 如 mapped statement, 要 执 行 的
IDbCommand,当前的 ResultMap 和 ParameterMap 等
看一下获取
DbCommand 的方法:
1 /// <summary>
2 /// 获取 DbCommand
3 /// </summary>
4 /// <param name="sqlMapper">ISqlMapper</param>
5 /// <param name="statementName">statement 的 id</param>
6 /// <param name="paramObject">sql 语句的参数</param>
7 /// <returns>DbCommand</returns>
8 protected virtual IDbCommand GetDbCommand(ISqlMapper sqlMapper, string
statementName, object paramObject)
9 {
10 IStatement statement = sqlMapper.GetMappedStatement(statementName).Statement;
11 IMappedStatement mapStatement = sqlMapper.GetMappedStatement(statementName);
12 ISqlMapSession session = new SqlMapSession(sqlMapper);
13
14 if (sqlMapper.LocalSession != null)
15 {
16 session = sqlMapper.LocalSession;
17 }
18 else