2010-08-04 47 views
1

当我使用NHibernate(我是一个初学者),我能够在输出中获得对Db的SQL调用。但是我复制并粘贴到Management Studio后无法使其工作。因为缺少参数声明。如何获取参数声明以及NHibernate的SQL调用?

我得到的是这样的:

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在创建的查询字符串中添加参数声明吗?

感谢

回答

3

建档我使用附带的Microsoft SQL Server Management Studio或NHibernate Profiler SQL Server事件探查。

在SQL Server Profiler中,您可以看到这些语句以及参数声明和值,因此您可以将它们复制并粘贴到管理工作室中。

在NHibernate分析器中,您还可以看到SQL语句,但参数已被替换为值(您可以在注释中看到参数名称)。我强烈推荐NHibernate profiler,你可以下载试用版。

-1

像这样的东西应该工作(没有测试过,我没有你的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);