【发布时间】:2013-10-30 16:24:35
【问题描述】:
简单的问题 - 我如何才能通过延迟加载仅返回集合的特定元素?
public virtual ICollection<Attachment> Attachments
{
get
{
return this.Attachments.Where(x => x.del != true) as ICollection<Attachment>;
}
set {
this.Attachments = value;
}
}
我只想返回这些<Attachment>,其中del != true。
使用此代码,我有错误:
“System.StackOverflowException”类型的未处理异常 发生在 EntityFrameworkDynamicProxies
无法计算表达式,因为当前线程在堆栈中 溢出状态。
为什么?我该怎么做?
问候
【问题讨论】:
-
this.Attachments指的是您的Attachments属性。它需要调用你的get方法。这需要调用您的get方法。这需要调用你的get方法。获取 R#。它会告诉您该方法在所有路径上都是递归的。 -
这里必须有一个支持字段。现在你处于无限递归中,直到堆栈溢出。
-
ohhhh,对我来说太早了 - 我忘了把
_Attachments而不是Attachments.. 无论如何谢谢大家 :)
标签: c# entity-framework asp.net-mvc-4