3

I use the LINQ DataContext's Log property to send the generatated SQL to the debug window. (There is a post by Kris Vandermotten about that). That works fine, except that the ouputted SQL parameters are some SQL comments, and so I can't run the query in Management Studio. Here's an example:

SELECT * FROM table WHERE id IN (@p0,@p1,@p2)
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [5]
-- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [1]
-- @p2: Input Int (Size = 0; Prec = 0; Scale = 0) [13189086]

So, is there any tool that transforms this text into a valid SQL?

2
  • Is your desired result just the SQL statement with all the parameter placeholders substituted with their values? Or did you still want the DECLARE statements included, similar to the LINQPad output in my response? Commented Nov 21, 2010 at 16:32
  • It wolud be nice to have parameters DECLAREd, but it's reasonable with the parameters substituted. The goal is to have a query ehich can be Executed. Commented Nov 22, 2010 at 7:21

1 Answer 1

2

You can grab LINQPad (free!) and run your LINQ to SQL directly. Then click on the "SQL" tab in LINQPad to see the generated SQL. It will DECLARE all the parameters for you and you could copy/paste that into SSMS (or click "Analyze SQL" from the SQL tab to launch it in SSMS). You can also run it directly from LINQPad.

Screenshot:

LINQPad

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it's a good entry, but not the answer i'm looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.