c# - 对对象进行多次提取会导致 Visual Studio 在编译时崩溃

标签 c# visual-studio-2010 nhibernate c#-4.0 queryover

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

不幸的是,我有一个域对象,它有很多关系(我无法改变这一点),本质上是当我构建查询时,只是简单地添加急切的提取,在添加一定数量后,构建时间急剧增加,直到最终 Visual Studio 卡住并崩溃。查询非常简单,看起来像这样:

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 锁定并最终永远无法完成 build 。

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

最佳答案

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

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

关于c# - 对对象进行多次提取会导致 Visual Studio 在编译时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14581092/

相关文章:

c# - 简单的 WPF 平移;这段代码很接近但不太正确

c# - xamarin 中的 NUnit 错误

c# - 在 Visual Studio Code 中找不到 Xunit 命名空间

vb.net - VB Visual Studio 不更新 bin/debug 文件夹

c# - DynamicActivity - 如何调用存储在数据库中的工作流?

nhibernate - NoSetter 和 ReadOnly 有什么区别?

c# - 无法找到 Net Core NHibernate System.Data.SQLite

c# - 防止 C# 中 HtmlButton 的回发

c++ - 模板编译: gcc vs VS2010

sql - 如何在不删除表的情况下更新数据库模式