我已经研究这个僵局问题好几天了,无论我做什么,它都以一种或另一种方式持续存在。
首先,一般前提:我们有访问与访问项的一对多关系。
访问项目相关信息:
CREATE TABLE [BAR].[VisitItems] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[VisitType] INT NOT NULL,
[FeeRateType] INT NOT NULL,
[Amount] DECIMAL (18, 2) NOT NULL,
[GST] DECIMAL (18, 2) NOT NULL,
[Quantity] INT NOT NULL,
[Total] DECIMAL (18, 2) NOT NULL,
[ServiceFeeType] INT NOT NULL,
[ServiceText] NVARCHAR (200) NULL,
[InvoicingProviderId] INT NULL,
[FeeItemId] INT NOT NULL,
[VisitId] INT NULL,
[IsDefault] BIT NOT NULL DEFAULT 0,
[SourceVisitItemId] INT NULL,
[OverrideCode] INT NOT NULL DEFAULT 0,
[InvoiceToCentre] BIT NOT …Run Code Online (Sandbox Code Playgroud) 我们正在使用nHibernate它从.NET代码生成查询。有时,某些查询会卡在sp_whoisactive列表中,我们无法找出原因。我有一种感觉,它与丢失或损坏的参数有关。sp_whoisactive但是,当我运行时,我只看到参数名称(在示例中:)@p0,而不是实际值。有没有办法在进程仍在运行时检索此信息?
例子:
SELECT
this_.Id as Id6_2_, this_.HRNumber as HRNumber6_2_,
this_.FirstName as FirstName6_2_, this_.LastName as LastName6_2_,
this_.StatusTypeID as StatusTy5_6_2_,
this_.PropertyId as PropertyId6_2_, this_.DepartmentGroupId as Departme7_6_2_,
property2_.PropertyID as PropertyID10_0_,
property2_.PropertyCode as Property2_10_0_,
property2_.LMSCode as LMSCode10_0_, property2_.PropertyName as Property4_10_0_,
property2_.Report as Report10_0_, department3_.Id as Id4_1_,
department3_.Name as Name4_1_, department3_.DisplayName as DisplayN3_4_1_
FROM
[dbo].[EmployeeDepartmentGroupView] this_
LEFT OUTER JOIN
[dbo].[Property] property2_ ON this_.PropertyId=property2_.PropertyID
LEFT OUTER JOIN
[dbo].[DepartmentGroup] department3_ ON this_.DepartmentGroupId=department3_.Id
WHERE
this_.HRNumber LIKE @p0;
Run Code Online (Sandbox Code Playgroud)
请注意,这是从 …
我们有一些代码可以分页查看 SQL 结果。(目前在 SQL Server 2008 上运行)
我们注意到当分页完成时,一些行没有返回。让我澄清一下:
nHibernate 生成 SQL 查询。我们正在做分页。如果我们按 100 页,nHibernate 生成连续 SQL 查询的方式是:
以上,在 nHibernate 级别没有 ORDER BY / 排序,最终结果是某些行永远不会出现在 nHibernate 中。我们推测这是由于 SQL 的任意排序造成的,因此行在页面内“移动”(从而从我们的应用程序代码中“隐藏”)。
如果我们单次执行 nHibrate 查询(返回所有行),我们会看到所有数据。(下面的这个查询是由 nhibernate 生成的。)
添加 order by 子句(又名 nHibernate 排序)有帮助吗?
SELECT top 33
... <field list>
FROM
salesOrder this_ left outer join [Item] Item2_ on this_.ItemId=Item2_.ItemId
WHERE this_.AccountId = @p0
and this_.ModifiedAt > @p1
and this_.ModifiedAt <= @p2
Run Code Online (Sandbox Code Playgroud)