Ad

How Does SQL Know What @p# In LINQtoSQL Queries?

- 1 answer

I want to know how does the SQL Server know what @p# is in say this LINQtoSQL query

SELECT 
    [t0].[MemberID], [t0].[Aspnetusername], [t0].[Aspnetpassword], 
    [t0].[EmailAddr], [t0].[DateCreated], [t0].[Location], 
    [t0].[DaimokuGoal], [t0].[PreviewImageID], 
    [t0].[LastDaimoku] AS [LastDaimoku], [t0].[LastNotefied] AS [LastNotefied], 
    [t0].[LastActivityDate] AS [LastActivityDate], [t0].[IsActivated]
FROM 
    [dbo].[Members] AS [t0]
INNER JOIN 
    [dbo].[MemberStats] AS [t1] ON [t0].[MemberID] = [t1].[MemberID]
WHERE 
    [t1].[TotalDeterminations] > @p0

When viewing SQL Server Profiler this is what gets executed against the database... but there is nothing telling SQL Server the value of @p0 so how does it know what that value is?

Ad

Answer

It's a parameterized query generated by LINQ to SQL so that the query plan can be cached by SQL Server for later reuse. The parameter value was sent to SQL Server upon execution, it's just that the RPC:Completed event does not show it, if I recall correctly.

Ad
source: stackoverflow.com
Ad