Behavior of Session Getters
<p>I have the following property for getting and setting a Session variable...</p>

<pre><code>protected List&lt;Item&gt; SearchResults
{
    get
    {
        if (Session["SearchResults"] == null)
            Session["SearchResults"] = new List&lt;string&gt;();
        return ((List&lt;string&gt;) Session["SearchResults"]).Select(s =&gt; new Item(s)).ToList();
    }
    set { Session["SearchResults"] = value.Select(p =&gt; p.Serialize()).ToList(); }
}
</code></pre>

<p>As you can see, I am storing the items as serialized strings.
When the user checks a few checkboxes in a GridView and then clicks submit, I would like to modify the value of the Selected property of the Items that he has selected. Here is my code for doing that and it is working great...</p>

<pre><code>private void RecordSelections()
{
    var searchResults = SearchResults; //localize session list
    foreach (var checkBox in AssignGrid.Rows.Cast&lt;GridViewRow&gt;().Select(r =&gt; (CheckBox)r.FindControl("chkSelect")))
    {
        var result = searchResults.FirstOrDefault(r =&gt; r.Key == long.Parse(checkBox.Attributes["ItemKey"].ToString()));
        if (result != null) result.Selected = checkBox.Checked;
        SearchResults = searchResults; //store session list
    }
}
</code></pre>

<p>My question then is this. I have found it necessary to localize the session list (see commented line) and then to store that session list (also commented), but what is it precisely that is happening when I access this Session variable through the getter? I would like to do something like the following to get an Item out of the list and modify it's value. I am not able to answer exactly why it is that this doesn't work. Would it work if I were not serializing the object (the reason for serializing the item is <a href="http://stackoverflow.com/questions/8199831/declaring-a-class-in-aspx-script-block-then-storing-it-in-session">another post</a> altogether)?</p>

<pre><code>private void RecordSelections()
{
    foreach (var checkBox in AssignGrid.Rows.Cast&lt;GridViewRow&gt;().Select(r =&gt; (CheckBox)r.FindControl("chkSelect")))
    {
        var result = SearchResults.FirstOrDefault(r =&gt; r.Key == long.Parse(checkBox.Attributes["ItemKey"].ToString()));
        if (result != null) result.Selected = checkBox.Checked;
    }
}
</code></pre>

<p>Thanks in advance for your help.</p>
