在我的系统中,我对包含大量集合的聚合进行集中计算。我需要在计算之前加载所有集合,因此我使用一个在根上联接集合的多标准。
我在下面列出的标准。在我的本地设置上运行大约需要500毫秒,这需要等待用户很多时间。有人知道我如何优化这个吗?感谢您提供的任何帮助,使本次查询更快!
(为了隐私起见,我更改了收藏的名称:)
IMultiCriteria criteria = session.CreateMultiCriteria()
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("ACollection", JoinType.LeftOuterJoin)
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("BCollection", JoinType.LeftOuterJoin)
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("CCollection", JoinType.LeftOuterJoin)
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("ECollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("FCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("GCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("HCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("JCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("KCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("LCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("MCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("NCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("OCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("PCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("QCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("RCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("SCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("TCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("UCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("VCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("WCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("XCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("YCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("ZCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("AACollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("ABCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("ACCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("ADCollection", JoinType.LeftOuterJoin))
.Add(DetachedCriteria.For<Building>()
.Add(Restrictions.Eq("Id", BuildingId))
.CreateCriteria("AECollection", JoinType.LeftOuterJoin));