Last active
December 22, 2015 00:39
-
-
Save neilgaietto/6390824 to your computer and use it in GitHub Desktop.
Debug the queries running through your LINQ to SQL DataContext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DebugTextWriter : System.IO.TextWriter | |
{ | |
public override void Write(char[] buffer, int index, int count) | |
{ | |
//output queries to "Output" window in visual studio | |
System.Diagnostics.Debug.Write(new String(buffer, index, count), "DBDebug"); | |
} | |
public override void Write(string value) | |
{ | |
//output queries to "Output" window in visual studio | |
System.Diagnostics.Debug.Write(value, "DBDebug"); | |
} | |
public override Encoding Encoding | |
{ | |
get { return System.Text.Encoding.Default; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RepositoryClass | |
{ | |
public DatabaseDataContext DataContext { get; private set; } | |
public RepositoryClass(string connectionString) | |
{ | |
DataContext = DataContext ?? new DatabaseDataContext(connectionString); | |
DataContext.Log = new DebugTextWriter(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment