Domanda

Quando prendo un changeconflictxception è possibile determinare l'istruzione SQL effettiva che non è riuscita entro il codice?cioè;piuttosto che ispezionare l'output del profiler.

È stato utile?

Soluzione

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 };
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top