我有一张表格,里面存储着使用NHibernate从我的web应用程序中查询的分层数据。这是很简单的在NHibernate中缓存公用表表达式(CTE)查询
CREATE TABLE [dbo].[Relationships](
[RelationshipId] [uniqueidentifier] NOT NULL,
[ParentId] [uniqueidentifier] NULL,
[ParentTypeId] [uniqueidentifier] NULL,
[ChildId] [uniqueidentifier] NOT NULL,
[ChildTypeId] [uniqueidentifier] NOT NULL
)
我们查询从该表中我使用SQL Server的一个特征信息(2005年以来)称为公用表表达式,或者CTE的简称。它可以让我编写递归查询,这对上表中的表格非常有用。现在
WITH Ancestors(RelationshipId, ParentId, ChildId)
AS
(
SELECT r.RelationshipId, r.ParentId, r.ChildId
FROM Relationships r
WHERE ChildId = :objectId
UNION ALL
SELECT r.RelationshipId, r.ParentId, r.ChildId
FROM Relationships r
INNER JOIN Ancestors
ON Ancestors.ParentId = r.ChildId
)
SELECT RelationshipId, ParentId, ChildId FROM Ancestors
,这是伟大的表现并不坏,但是当我尝试使用它来确定祖先往上走的树,或者更糟,使用类似的查询,以确定decendants可以征税。
现在我想简单地缓存这个查询的结果,但是如果我有.SetCacheable(true)
,我得到nHibernate Index was outside the bounds of the array.
的错误。如果我删除缓存支持查询工作正常。
查询工作正常,如果我从我的电话中删除缓存支持Session.CreateSQLQuery()
现在我已经在线寻找尝试找到一个原因,但我没有找到我发现的结果中的共识。
所以,虽然我很好奇为什么它不起作用,我更感兴趣的是寻找一种解决方法,让缓存与我的CTE在nHibernate中一起工作?