2

我有一个奇怪的问题让我完全难住了。

不幸的是,我有一个域对象,它有很多关系(我不能改变这个),基本上当我建立我的查询并且只是简单地添加急切的获取时,在我添加一定数量之后,构建时间会急剧增加直到最终视觉工作室只是冻结和崩溃。查询非常简单,看起来像这样:

var query = QueryOver<DomainObject>
.Fetch(x => x.Property).Eager
.Fetch(x => x.Property.PropertyA).Eager
.Fetch(x => x.Property.PropertyB).Eager
.Fetch(x => x.Property.PropertyC).Eager
.Fetch(x => x.Property.PropertyD.SubProp).Eager
.Fetch(x => x.Property.PropertyE).Eager
.Fetch(x => x.Property.PropertyF.SubProp).Eager
.Fetch(x => x.Property.PropertyG).Eager
.Fetch(x => x.Property.PropertyH.SubProp).Eager
.Fetch(x => x.Property.PropertyI).Eager
.Fetch(x => x.Property.PropertyJ).Eager
.Fetch(x => x.Property.PropertyK).Eager
.Fetch(x => x.Property.PropertyL).Eager
.Fetch(x => x.Property.PropertyM).Eager
.Fetch(x => x.Property.PropertyN).Eager
.Fetch(x => x.Property.PropertyO).Eager
.Fetch(x => x.Property.PropertyP).Eager
.Where(x => x.Id == 5);
//My fingers got tired there are in reality 33 fetches, 29 involve x.Property

query.Clone()
.Fetch(x => x.Property.PropertyN.ListProperty).Eager
.Future();

query.Clone()
.Fetch(x => x.PropertyO.ListProperty).Eager
.Future();

query.Clone()
.Fetch(x => x.PropertyD.ListProperty).Eager
.Future();

query.Clone()
.Fetch(x => x.PropertyH.ListProperty).Eager
.Future();

var results = query.Future().ToList();

这基本上是我们正在查看的查询的伪查询,如果我注释掉提取部分,它构建得很好(仍然比其他项目慢),因为我一次取消注释一个提取,构建时间增加,直到最终 Visual Studio 锁定并最终永远不会完成建筑。

有没有人对此有任何线索?我曾尝试在互联网上搜索,但完全找不到任何相关信息,目前延迟加载似乎是我唯一的选择。但是,我真的很想回答这个问题。

4

1 回答 1

2

因此,如果问题在于编译器对方法链的大小有限制,那么解决方案(理论上)会很简单:

var query = QueryOver.Of<DomainObject>();
query = query.Fetch(x => x.Property).Eager;
query = query.Fetch(x => x.Property.PropertyA).Eager;
query = query.Fetch(x => x.Property.PropertyB).Eager;
query = query.Fetch(x => x.Property.PropertyC).Eager;
// etc
于 2013-01-30T03:14:00.280 回答