Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 838913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:22:55+00:00 2026-05-15T05:22:55+00:00

I want to see what my insert statement would look like as if I

  • 0

I want to see what my insert statement would look like as if I was wiring
up an text-based ADO.NET command. How do I do this?

I have been following the below link:

http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers

And have added the DebugTextWriter class to my project. So, now, in my code I have the following which doesn’t really do anything and I don’t think its right:

    using(WorkbookDataContext dc = _conn.GetContext())
    {
        if(profile.ProfileId > 0)
        {
            dc.Profiles.Attach(profile, true);
        }
        else
        {
            dc.Profiles.InsertOnSubmit(profile);
        }

        dc.Log = new DebugTextWriter();

        #if DEBUG
            dc.Log = new System.IO.StreamWriter("linq-to-sql.log") 
            { 
                 AutoFlush = true 
            };
        #endif


        dc.SubmitChanges();
    }

Any ideas what I am doing wrong and/or how to inspect my LINQ insert statement correctly?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:22:56+00:00Added an answer on May 15, 2026 at 5:22 am

    How to: Display Generated SQL (LINQ to SQL)

    You can view the SQL code with the Log property.

    Example: use the Log property to display SQL code in the console window before the code is executed.
    You can use this property with query, insert, update & delete commands.

    db.Log = Console.Out;
    IQueryable<Customer> custQuery =
        from cust in db.Customers
        where cust.City == "London"
        select cust;
    
    foreach(Customer custObj in custQuery)
    {
        Console.WriteLine(custObj.CustomerID);
    }
    

    These lines from the console window are what you see when you execute the C# code above.

    SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactT
    itle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Coun
    try], [t0].[Phone], [t0].[Fax]
    FROM [dbo].[Customers] AS [t0]
    WHERE [t0].[City] = @p0
    -- @p0: Input String (Size = 6; Prec = 0; Scale = 0) [London]
    -- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.20810.0
    
    AROUT
    BSBEV
    CONSH
    EASTC
    NORTS
    SEVES
    

    Alternately, you can use the LINQ to SQL Debug Visualizer to hover over a LINQ expression while in the VS 2008 debugger, and then inspect the raw SQL that the ORM will execute at runtime when evaluating the LINQ query expression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to combine insert/update with a case statement, meaning that I want
I want to see a list of all changes the next push would do.
I want to see the source of functions like ns_initparse(), res_search() etc. Where can
I want to see class, function and variable/property, dependencies visually, like NDepend , but
I would like to put an int into a string . This is what
Let's say I have a table and I want to insert a row. The
I'm inserting hundreds of rows into a Local Database. After this insert, I would
I would like to know how hibernate work... Lets say that I have three
In a trigger I want to see what sql query triggered this trigger. I
I want to insert some data to mydatabase.sqlite but I have a problem. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.