x.AddrZip==p1); var sql...">

How can I see the parameters of an IQueryable expression

If i do

var p1 = "33326";
var query = Db.Customers.Where(x=>x.AddrZip==p1);

var sqlStatement = query.ToString(); 
            /*
             sqlStatement =
                SELECT 
                [Extent1].[Id] AS [Id], 
                [Extent1].[FirstName] AS [FirstName], 
                [Extent1].[LastName] AS [LastName], 
                [Extent1].[Company] AS [Company]                    
                FROM [dbo].[Customers] AS [Extent1]
                WHERE [Extent1].[AddrZip] = @p__linq__0
             */

Notice at the end of the request I see @p__linq__0. where is the parameter on query? I am looking to find something likequery.Parameters

Edit

Sorry, I forgot to mention that Db is of type DbContextand notDataContext

+3
source share
2 answers

Itself IQueryabledoes not know anything about parameters - this is a more general interface, and the concept of parameters depends on a specific implementation.

However, you can use the method DataContext.GetCommandto verify the received command. The resulting object DbCommandhas a set of parameters:

DbCommand command = Db.GetCommand(query);
var parameters = command.DbParametersCollection;
+2
source

CommandFinished .

 context.CommandFinished += (sender, e) =>
  {
    Console.WriteLine("Command has finished: {0}", e.ToTraceString());
  }; 
0

All Articles