MonoTouch的&安培; LINQ - 操作是无效的,由于对象的当前状态 [英] MonoTouch & LINQ - Operation is not valid due to the current state of the object

查看:266
本文介绍了MonoTouch的&安培; LINQ - 操作是无效的,由于对象的当前状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Mac上使用MonoTouch的/ C#作为前端,在VS2010从WCF服务拉动后端数据的应用程序。一切都被昨晚的工作就像一个梦在我离开之前,今天,我不知道发生了什么事。所有我能看到的是,这是一个从MonoTouch的的LINQ中来个例外,它看起来像我做的一切OK,因为我还没有触及这段代码中的最后几天。

I have an application that uses Monotouch/C# on the Mac as the front end, pulling data from a WCF service in VS2010 on the backend. Everything was working like a dream last night before I left, and today, I'm not sure what's going on. All I can see is that it's an exception coming from within Monotouch's linq, and it looks like I'm doing everything OK, as I haven't touched this piece of code in the last few days.

在我收到了 GetAllStaffResult 对象从WCF回来,我让自己回主线程,然后调用此方法填充()

After I get a GetAllStaffResult object back from WCF, I get myself back into the main thread and then call this method Populate():

public void Populate()
{
    foreach (var m in Staff)
    {
        m.FranchiseName = this.Franchises.Single(f => f.ID == m.FranchiseID).Name;
    }
    [snip]
}

下面是堆栈跟踪

System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Linq.Enumerable.First[FranchiseListingItem] (IEnumerable'1 source, System.Func2 predicate, Fallback fallback) [0x0004a] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:816
at System.Linq.Enumerbale.First [FranchiseListingItem] (IEnumerable'1 source, System.Func2 predicate) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:843
at ADMobileServices.BOTransferDTOs.GetAllStaffResult.Populate() [0x0003b] (my code)

不知道是什么可能会导致这...任何人有什么想法?要看到,如果我能找到MT源文件,这样我就可以看到这些行。

Not sure what could be causing this... anyone have any ideas? Going to see if I can find MT source files so I can see those lines.

哦,这个是一个 GetAllStaffResult ,上面的方法是有工作人员,特许经营权,位置阵列的部分类。该填充方法将每个工作人员,并根据员工的专营权ID专营权的名称。我这样做,因为我喜欢回500名工作人员用长专营权的名字,我通过重建客户端上的对象图自己身边节省带宽。

Oh, this is a GetAllStaffResult, the method above is a partial class which has an array of staff members, franchises, locations. The populate method takes each staff member and populates the name of the franchise based on the staff's franchise ID. I'm doing this because I'm returning like 500 staff members with long franchise names and I'm saving bandwidth by reconstructing the object graph on the client side myself.

因为在数据库中的外键关系,我100%肯定,单身始终会返回一个结果。首先()给了我同样的问题太多

Because there is a foreign key relationship in the database, I'm 100% certain that Single will always return a result. First() gave me the same problem too.

编辑:堆栈跟踪是我单()方法后尝试的第()方法。我检查出的源代码现在,将报告我的发现。

The stack trace is for the First() method which I tried after the Single() method. I'm checking out the source code now, will report my findings.

推荐答案

这将如果序列是空的发生。

This would happen if the sequence is empty.

这篇关于MonoTouch的&安培; LINQ - 操作是无效的,由于对象的当前状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆