我想知道在将参数解析为sql字符串之后是否可以看到sql语句的实际内容.例如,给出以下代码:
const string sql = @" SELECT * FROM V_PROVIDER_WAGE_OVER_REVENUE WHERE SITE_ID = :SITE_ID AND VENDOR_ID = :VENDOR_ID AND date_paid >= :DATE_FROM AND date_paid <= :DATE_TO;"; conn.Query<ProviderWageOverRevenueModel>(sql,new { VENDOR_ID = vendorId,SITE_ID = siteId,DATE_FROM = dateFrom,DATE_TO = dateTo }).ToList();
我想知道是否在某些时候(也许在Dapper源内?)我能看到类似的东西:
SELECT * FROM V_PROVIDER_WAGE_OVER_REVENUE WHERE SITE_ID = 199 AND VENDOR_ID = 17 AND date_paid >= '01/01/2014' AND date_paid <= '20/11/2014';
编辑
我假设参数占位符将被替换为值,但是仔细观察Dapper的来源后,我意识到它只是在iDbCommand上执行查询,所以看完这个question之后就可以看到执行了在.Net内的声明?
我试试这个:
string query = cmd.CommandText; foreach (DbParameter p in cmd.Parameters) { query = query.Replace(p.ParameterName,p.Value.ToString()); }
但结果似乎并不像我希望的那样:
SELECT * FROM V_PROVIDER_WAGE_OVER_REVENUE WHERE 23411127316 = :23411127316 AND 23411076816 = :23411076816 AND date_paid >= :1/07/2014 10:11:34 PM AND date_paid <= :12/12/2014 12:00:00 AM;