C# 如何获取参数声明以及NHibernate的SQL调用?
当我使用NHibernate时(顺便说一句,我是它的初学者),我能够在输出中获得对Db的SQL调用。但在复制并粘贴到ManagementStudio之后,我无法让它们工作 因为它缺少参数声明。 我得到的结果是:C# 如何获取参数声明以及NHibernate的SQL调用?,c#,.net,sql,nhibernate,C#,.net,Sql,Nhibernate,当我使用NHibernate时(顺便说一句,我是它的初学者),我能够在输出中获得对Db的SQL调用。但在复制并粘贴到ManagementStudio之后,我无法让它们工作 因为它缺少参数声明。 我得到的结果是: SELECT this_.PK_Product as PK1_1_0_, this_.ProductCode as ProductC2_1_0_ , this_.ProductName as ProductN3_1_0_, this_.ProductCodeISO2 as Product
SELECT this_.PK_Product as PK1_1_0_, this_.ProductCode as ProductC2_1_0_
, this_.ProductName as ProductN3_1_0_, this_.ProductCodeISO2 as ProductC4_1_0_
, this_.NotUsed as NotUsed1_0_, this_.Confirmed as Confirmed1_0_, this_.LabelRequired as LabelReq7_1_0_ FROM tProduct this_
WHERE (this_.NotUsed = @p0 and this_.Confirmed = @p1 and this_.LabelRequired = @p2);@p0 = False [Type: Boolean (0)], @p1 = True [Type: Boolean (0)], @p2 = False [Type: Boolean (0)]`enter code here`
当我在SQL Management Studio中执行此操作时,我得到一个错误:
味精137,第15级,第2状态,第1行
必须声明标量变量“@p0”
我可以告诉NHibernate在创建的查询字符串中添加参数声明吗?
感谢您分析我使用的是Microsoft SQL Server Management Studio或提供的SQL Server Profiler 在SQL Server Profiler中,您可以看到这些语句以及参数声明和值,因此您可以将它们复制并粘贴到management studio中
在NHibernate探查器中,您还可以看到SQL语句,但是参数已经被值替换(您可以在注释中看到参数名称)。我强烈推荐NHibernate profiler,您可以下载试用版。类似的功能应该可以使用(未经测试,我没有您的DB):
DECLARE @p0 BIT
DECLARE @p1 BIT
DECLARE @p2 BIT
SET @p0 = 0
SET @p1 = 1
SET @p2 = 0
SELECT
this_.PK_Product as PK1_1_0_,
this_.ProductCode as ProductC2_1_0_,
this_.ProductName as ProductN3_1_0_,
this_.ProductCodeISO2 as ProductC4_1_0_,
this_.NotUsed as NotUsed1_0_,
this_.Confirmed as Confirmed1_0_,
this_.LabelRequired as LabelReq7_1_0_
FROM tProduct this_
WHERE
(this_.NotUsed = @p0 and this_.Confirmed = @p1 and this_.LabelRequired = @p2);