Question

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....

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top