IQueryable上的 C# Foreach

发布于 2024-11-04 05:59:40 字数 997 浏览 4 评论 0原文

我在以下代码中遇到 stackoverflow 异常...

IQueryable<MilestoneList> ml = from MilestoneList d in this.getDB().AsQueryable<MilestoneList>()
                                         where d.Contains((Milestone)toDelete) == true
                                         select d;
                if (ml.Count() > 0)
                {
                    foreach (MilestoneList m in ml)
                    {
                        m.Remove((Milestone)toDelete);
                        this.getDB().Store(m);
                    }
                }

我的 MilestoneList 对象已实现 IEnumerable 和 IEnumerator。

但我认为循环遍历这些对象的列表应该不是问题。 有人有什么建议可以推动我找到解决方案吗?

根据要求提供更多信息。

更新&回答:

问题似乎出在 Contain 函数上。 这是一个令人尴尬的错误.. 对于您失去的时间深表歉意..

public bool Contains(Milestone m)
    {
        Activate(ActivationPurpose.Read);
        return this._mList.Contains(m);
    }

我忘记了参考我的内部列表。所以我通常创建了一个无限循环。

I'm getting stackoverflow exceptions on the following code...

IQueryable<MilestoneList> ml = from MilestoneList d in this.getDB().AsQueryable<MilestoneList>()
                                         where d.Contains((Milestone)toDelete) == true
                                         select d;
                if (ml.Count() > 0)
                {
                    foreach (MilestoneList m in ml)
                    {
                        m.Remove((Milestone)toDelete);
                        this.getDB().Store(m);
                    }
                }

My MilestoneList object had IEnumerable and IEnumerator implemented.

But looping through a list of those objects shouldn't be problem I assume.
Anybody has any tips for pushing me in a direction towards a solution?

more info on request.

update & Answer :

The problem seems to be at the Contain function.
It was an embarrassing mistake.. sorry for your lost time..

public bool Contains(Milestone m)
    {
        Activate(ActivationPurpose.Read);
        return this._mList.Contains(m);
    }

I forgot the to refer to my internal list. So I generaly created an infinite loop.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2024-11-11 05:59:40

更新&回答:

问题似乎出在 Contain 函数上。这是一个令人尴尬的错误.. 对于您失去的时间深表歉意..

public bool Contains(Milestone m)
    {
        Activate(ActivationPurpose.Read);
        return this._mList.Contains(m);
    }

我忘记了参考我的内部列表。所以我通常创建了一个无限循环。

update & Answer :

The problem seems to be at the Contain function. It was an embarrassing mistake.. sorry for your lost time..

public bool Contains(Milestone m)
    {
        Activate(ActivationPurpose.Read);
        return this._mList.Contains(m);
    }

I forgot the to refer to my internal list. So I generaly created an infinite loop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文