linq to sql - How to get the sql update method generated by LinqToSql? -


How to obtain the SQL generated by LinqToSql for the update method?

I use the following code to show the generated SQL in the debug output window of the VS2008 by LinqToSql, but this only generates the SQL selection method,

How do I use SQLQL method Can I locate the SQL method generated by? I can know SQL Server Profiler and Linux (SQL-Update Generated), but I want to show them in VS-2008 or log them into the file.

  Public Partial Category Linq2: System.Web.UI.Page {Secure Zero Page_load (Object Sender, EventArgs e) {DemoDataContext ctx = new DemoDataContext (); // Then attach it to your DataContext log property ... ctx.log = new DebugTextWriter (); Var Product = CTX Products FirstOver Default (); Product.ProductName = "NewName1"; Ctx.SubmitChanges (); }} // Add this project to your project somewhere ... Public Category Debug TextDriver: System IoTexture {write public override zero (four [] buffer, int index, int counting) {System.Diagnostics.Debug.Write (new string (buffer, index, count)); } Write public override zero (string value) {System.Diagnostics.Debug.Write (value); } Public override encoding encoding {get {return System.Text.Encoding.Default; }}}  

and I get the SQL-select query in the VS2008 debug output window:

  SELECT TOP (1) [t0]. [ID], [T.]. [Product Name] ...... from [DBO] [Product] AS [T] - Reference: SQL ProvWidder (SK-2005) Model: Attitated Matermodel Build: 3.5.3072 9.1  

Your database reference object is a log method that you can override your full update statement, and each SQL command generated by Linq-to-SQL, can be captured through this log method is. I know this work because I use it to catch all our questions in our app. Just keep in mind that L2S can send the output to the appropriate amount in the log method, so be sure to capture it all. Your update statement is somewhere.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -