IEnumerable
is a query that is lazily evaluated. But apparently my understanding is a bit flawed. I'd expect the following to work:
// e.Result is JSON from a server
JObject data = JObject.Parse(e.Result);
JsonSerializer serializer = new JsonSerializer();
// LINQ query to transform the JSON into Story objects
var stories = data["nodes"].Select(
obj => obj["node"]).Select(
storyData => storyOfJson(serializer, storyData));
// set a value on each story returned by the query
foreach (Story story in stories)
{
story.Vid = vid;
}
// run through the query again, making sure the value was actually set
foreach (Story story in stories)
{
// FAILS - story.VID is 0
Debug.Assert(story.Vid == vid);
}
What am I misunderstanding here? How can I alter the results of what this query returns?