简体   繁体   English

如何使用Nhibernate通过递归自联接SQL获得最佳性能

[英]How to get optimal performance with recursive self join SQL using nhibernate

I have a Team table /entity with a parentId which is an id that self joined into the same table. 我有一个带有parentId的团队表/实体,该ID是自我加入同一表的ID。

There is a property called TopUnit that will recursizely keep calling .Parent until it finds an attribute on the Team entity called "IsTopUnit" 有一个名为TopUnit的属性,它将递归地继续调用.Parent,直到在Team实体上找到一个名为“ IsTopUnit”的属性为止

using the nhibernate profiler this is now causing an Select N + 1 alert. 使用nhibernate探查器,这现在会引起Select N + 1警报。 is there anyway to optimize what is essentially a recursize self join query to avoid the Select N + 1 behavior. 无论如何,有什么方法可以优化本质上是递归大小的自联接查询,从而避免Select N +1行为。

batchsize seems to work for child collections but it doesn't seems to help in this case as its all "syncronous" as i can't do a recursize SQL statement. batchsize似乎适用于子集合,但在这种情况下似乎没有帮助,因为它全部“同步”,因为我无法执行recursize SQL语句。

I guess this question is valid outside of nhibernate as well. 我想这个问题在nhibernate之外也是有效的。 What is the best way to do recursive statements in SQL. 在SQL中执行递归语句的最佳方法是什么。 it seems like you would have to break it up into multiple queries. 似乎您必须将其分解为多个查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM