Linq to Sql: Change Conflict SQL Statement
When I catch a ChangeConflictExceptio开发者_StackOverflow中文版n is it possible to determine the actual SQL statement that failed from within the code? ie; rather than inspecting profiler output.
I hope I was not asking this question to attempt to perform some kind of optimistic concurrency re-syncing or reporting on fields (which is better performed via DataContext.ChangeConflicts
). But anyhow...
You can access the SQL statements executed by the DataContext at anytime provided you log them via DataContext.Log. A very good tutorial of using this can be found here.
An example of writing this to file;
db.Log = new System.IO.StreamWriter("linq-to-sql.log") { AutoFlush = true };
精彩评论