views:

61

answers:

2

I'm building up a query using LINQ to SQL and C# and when I inspect the final T-SQL that is built the where clause looks like this:

WHERE ([t0].[T_SUBJECT] LIKE @p0) AND ([t0].[T_SUBJECT] LIKE @p1)

The structure of the T-SQL looks correct and I can test it using SQL Server Management Studio (SSMS) but in the code it's not working. I'd like to be able to take a look at the values for @p0 and @p1. Anyone know how to inspect these values using VS2008?

+2  A: 

If you set the log for the context (with the Log property), it should show you the values as it executes the query. That may not be as handy as being able to examine them beforehand, but it's better than nothing.

For example, you might get something like (example shamelessly pinched from book):

SELECT [t0].[UserID], [t0].[Name], [t0].[UserType]
FROM [dbo].[DefectUser] AS [t0]
WHERE [t0].[Name] = @p0
-- @p0: Input String (Size = 11; Prec = 0; Scale = 0) [Tim Trotter]

The last line is the bit showing the actual parameter value.

Jon Skeet
Jon Skeet you rock! Thank you!
Guy
A: 

Try this: How to: Display Generated SQL (LINQ to SQL)

Quoting from there: The following example uses 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, and delete commands.

The lines from the console window are what you would see when you execute the Visual Basic or C# code that follows.

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
DOK