1

When you log LINQ-to-SQL's query output via the Log property on the DataContext object, you get output similar to:

SELECT [t0].[fullaname], [t0].[Worker], [t0].[Office]
FROM [dbo].[Workers] AS [t0]
WHERE [t0].[OfficeID] = @p0
ORDER BY [t0].[Name]
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [412]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1

In this example, I'm just pulling back some information about every Worker in the Office with ID = 412. However, this output does not execute directly in a SQL Management Studio Query window, because of the @p0 commented format that LINQ outputs.

Does anyone know if there is a stored procedure that takes this format so I can execute it? I looked at the paramaterized query procs, but maybe I'm just not seeing it. If there's no procedure, I'm about to write a parser that will turn this format into "normal" SQL...

Thanks!

Note:

I know I could just Define @p0 at the top of this, as shown in Help with SQL/LINQ Debugging, but - a lot of these queries I have take like 20 parameters, so it becomes a lot of work copying and pasting....

1 Answer 1

1

There is no way to directly execute what you have above without manually (or programattically via some kind of parse) inserting the value of the parameters.

If you use sql profiler you will get an executable dynamic sql statement, this is a much better approach, but i realise that this isn't always possible.

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

2 Comments

Yeah - I guess I could always turn on profiler...though it's nice to be able to grab it right from your dev environment, using DebuggerWriter, for instance: u2u.info/Blogs/Kris/Lists/Posts/Post.aspx?ID=11
I ended up writing a Regex parser that does search and replace on the necessary values. It's nice to be able to easily execute it now!

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.