using (MyEntityContext db = new MyEntityContext())
{
db.Log = new OutputDebugWriter();
...
}
class OutputDebugWriter : System.IO.TextWriter
{
public override void Write(char[] buffer, int index, int count)
{
System.Diagnostics.Debug.Write(new string(buffer, index, count));
}
public override void Write(string value)
{
System.Diagnostics.Debug.Write(value);
}
public override Encoding Encoding
{
get { return System.Text.Encoding.Default; }
}
}
Just some random development ramblings mostly related to the Microsoft .NET platform.
Showing posts with label Debug. Show all posts
Showing posts with label Debug. Show all posts
Monday, July 19, 2010
Entity Framework: How to log generated SQL in ASP.NET
If you want to log/view the generated T-SQL from your Entity Framework context instances to the output window in Visual Studio create a TextWriter derivation and use it like so:
Subscribe to:
Posts (Atom)
Can't RDP? How to enable / disable virtual machine firewall for Azure VM
Oh no! I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore. I did ...
-
Don't want Office 2007 installed on your web server to access Excel 2007 content? Here is a Visual Studio C# solution that demonstrates ...
-
I finally found a good algorithm to validate a file path (had to fix two bugs in it though). I use this static method in Windows Forms when...