Using Visual Studio 2010, .NET 4 as a Console App.
With a breakpoint on the close of the using statement, Visual Studio shows the select statement when hovering over “stuff”. However, “stmt1” and “stmt2” are both empty. Why?
Thanks.
Console app:
using ( var cona = new mydbcontext(connstring) )
{
var stuff = from a in cona.testtable select a;
var stmt1 = cona.SqlStatement;
string stmt2 = cona.GetLoggedInformation();
}
and
public partial class mydbcontext : DataContext
{
private StringBuilder bldr = new StringBuilder();
partial void OnCreated()
{
this.CommandTimeout = 120;
this.Log = new StringWriter(bldr);
}
public String GetLoggedInformation()
{
return bldr.ToString();
}
public string SqlStatement
{
get { return this.bldr.ToString(); }
}
}
Most likely, the log is not written until the statement is executed.
Try this