问题
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