天天看點

ibatisNet 在運作時擷取SQL的方法與限制

 1 、需引入如下4個namespace:

using IBatisNet.DataMapper;
using IBatisNet.DataMapper.Configuration;
using IBatisNet.DataMapper.MappedStatements;
using IBatisNet.DataMapper.Scope;      
2、将下面語句添加到代碼去,result 即為擷取的SQL      
ISqlMapper sqlMapper = new DomSqlMapBuilder().Configure();
                IMappedStatement statement = sqlMapper.GetMappedStatement("getlist");
                ISqlMapSession session = new SqlMapSession(sqlMapper);
                if (sqlMapper.LocalSession != null)
                {
                    session = sqlMapper.LocalSession;
                }
                else
                {
                    session = sqlMapper.OpenConnection();
                }
                RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, ht, session);
                   
                string resultSQL = scope.PreparedStatement.PreparedSql;      

 -------------------------

以上參考: ​

3、ibatis擷取正在執行的sql 限定條件

a、不可用## 來擷取字元串,隻能用 $$

b、必須傳入對象Hashtable key value關系 然後直接