我有一个奇怪的问题,让我完全难过。
不幸的是,我有一个域对象,它上面有很多关系(我不能改变它),基本上当我构建我的查询并只是添加一些数量的构建时,只需添加热切的提取时间急剧增加,直到最终视觉工作室冻结和崩溃。查询很简单,看起来像这样:
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锁定起来并最终永远不会完成建设。
有人对此有任何疑问吗?我试过在互联网上搜索,但我找不到任何相关信息,目前懒加载似乎是我唯一的选择。但是我真的很想回答这个问题。
答案 0 :(得分: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