Cancel DataServiceCollection: Only a single enumeration is supported by this IEnumerable

天大地大妈咪最大 提交于 2021-02-11 18:11:49

问题


Reference to my previous question asked today in the following link

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;

then:

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:

Only a single enumeration is supported by this IEnumerable.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/20104249/cancel-dataservicecollection-only-a-single-enumeration-is-supported-by-this-ien

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!