I would like to know if it is possible to see what the SQL statement looks like after the parameters have been parsed in an SQL string. For example, given the following code:
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();
I would like to know if at some point (maybe in the Dapper source?) I can see something like:
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';
Edit
I assumed that the placeholders parameters would be replaced by values, however, looking carefully at the Dapper source, I understand that its just relaying to iDbCommand fulfilled the request, therefore, looking at this question Can I see the executable operator inside .Net?
I try this:
string query = cmd.CommandText; foreach (DbParameter p in cmd.Parameters) { query = query.Replace(p.ParameterName, p.Value.ToString()); }
however, the result does not seem as I hope:
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;
source share