如果我这样做
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
*/
请注意,在查询结束时,我看到@p__linq__0
。 query
上的那个参数在哪里?我希望找到类似query.Parameters
抱歉,我忘了提及Db的类型为DbContext
且不是DataContext
答案 0 :(得分:2)
IQueryable
本身对参数一无所知 - 它是更通用的接口,参数的概念取决于特定的实现。
但是,您可以使用DataContext.GetCommand
方法检查生成的命令。生成的对象DbCommand
具有参数集合:
DbCommand command = Db.GetCommand(query);
var parameters = command.DbParametersCollection;
答案 1 :(得分:0)
您需要将事件CommandFinished用于上下文Look here以获取更多详细信息
context.CommandFinished += (sender, e) =>
{
Console.WriteLine("Command has finished: {0}", e.ToTraceString());
};