取消 DataServiceCollection:此 IEnumerable 仅支持单个枚举 [英] Cancel DataServiceCollection: Only a single enumeration is supported by this IEnumerable

查看:32
本文介绍了取消 DataServiceCollection:此 IEnumerable 仅支持单个枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考我今天在以下链接

我需要帮助编写一些代码来取消客户端的更改而不重新加载数据.我所做的唯一尝试是不成功的,如下所示:

I need help to write some code to cancel the changes on the client side without reloading the data. The only try I did was unsuccessfully as the following:

private IEnumerable<TheEntity> _data;

然后:

private void DoCancel()
{
    _dataSource.Clear(true);
    _dataSource.Load(data);
}

我以为我可以清除数据并重新加载缓存的私有字段.不幸的是,我收到错误:

I thought that I can clear the data and re-load a cached private field. Unfortunately, I get the error:

此 IEnumerable 仅支持单个枚举.

推荐答案

我希望这个时候能解决这个问题,但以防万一有人像我一样偶然发现了这个 :).真正的问题是我的代码从 IEnumerable 集合访问数据的方式.在您的示例中(来自提供的链接),该方法正在返回 Async 结果,而早些时候您正在对它执行 .ToList .

I hope this should be resolved by this time, but just in case if someone stumbled on this, like me :). The real issue was the way my code was accessing the data from the IEnumerable collection. In your example (from provided link) the method was returning Async results and earlier you were doing .ToList<T> on it.

您已更新以更正实施,但一旦收集,您将直接将其分配给数据源.为了解决这个问题,我首先收集了对变量的响应,然后将其转换为 .ToList.一旦我有了本地列表,我就可以根据需要分配/遍历任意多次.而由于 linq 的延迟绑定特性,一旦调用它就无法向后/向前遍历.(DataServiceCollection 可能存在一些内部实现问题.)

You have updated to correct implemntation, but once collected you are directly assigning it to datasource. To overcome this issue I had collected the response to a variable first and then convert it .ToList<T>. Once I have local list I can assign/traverse as many time as I want. Whereas with due to lazy binding nature of linq it was unable to traverse backward/forward once called.(There might have some internal implementation issue with DataServiceCollection.)

我希望这会对某人有所帮助.

I hope this will help someone.

这篇关于取消 DataServiceCollection:此 IEnumerable 仅支持单个枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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