1

简单的问题 - 我如何才能通过延迟加载仅返回特定的集合元素?

    public virtual ICollection<Attachment> Attachments
    {
        get
        {
            return this.Attachments.Where(x => x.del != true) as ICollection<Attachment>;
        }
        set {
            this.Attachments = value;
        }
    }

我只想返回这些<Attachment>,在哪里del != true

使用此代码,我有错误:

EntityFrameworkDynamicProxies 中出现“System.StackOverflowException”类型的未处理异常

无法计算表达式,因为当前线程处于堆栈溢出状态。

为什么?我该怎么做?

问候

4

1 回答 1

1
public virtual ICollection<Attachment> Attachments
{
    // defines get_Attachments
    get
    {
                    // calls get_Attachments
        return this.Attachments.Where(x => x.del != true) as ICollection<Attachment>;
    }

您的get_Attachments方法在所有路径上都是递归的。该方法将被调用,直到堆栈溢出。该视频应该可以帮助您可视化导致堆栈溢出的事件

看来您没有ReSharperReSharper 可以检查这些类型的错误。您应该安装试用版。

于 2013-10-30T08:24:35.633 回答