Introduction
Following on from How to configure Fluent NHibernate to output queries to Trace or Debug instead of Console? the answer provided there nicely outputs information to the console with the exception that it outputs ?
instead of the actual values of parameters.
Additionally using ShowSql()
does not output any UPDATE
lines.
Question
Is there a way to view the UPDATEs, parameters and all in the debug console?
Details of implementations
Using Interceptor
From How to configure Fluent NHibernate to output queries to Trace or Debug instead of Console?, I have implemented the following:
private class Interceptor : EmptyInterceptor
{
public override SqlString OnPrepareStatement(SqlString sql)
{
var s = base.OnPrepareStatement(sql);
Debug.WriteLine(s.ToString());
return s;
}
}
//...
var factory = Fluently.Configure()
// ...
.ExposeConfiguration(c => c.SetInterceptor(new Interceptor())
// ...
which results in outputs like
UPDATE [User] SET Email = ?, HashedPassword = ?, Name = ? WHERE Id = ?
Using ShowSql()
From this blog I have implemented the following
public class CustomDebugWriter : System.IO.TextWriter
{
public override void WriteLine(string value)
{
Debug.WriteLine(value);
base.WriteLine(value);
}
public override void Write(string value)
{
Debug.Write(value);
base.Write(value);
}
public override System.Text.Encoding Encoding
{
get { return new UTF8Encoding(); }
}
}
// ...
Console.SetOut(new CustomDebugWriter());
var dbConfig = MsSqlConfiguration.MsSql2012.ConnectionString(
c => c.FromConnectionStringWithKey(connectionStringKey));
dbConfig.ShowSql();
which doesn't output UPDATE statements at all.