title: How do I cast a ASP.NET session to get back my list?
body: <p>Background:  I have two web pages, one is a list of things, and the other is the detail of the thing.  On the list, the user can filter and sort, which results in a sorted list.  On the details, I would like the user to have Next and Previous navigation.</p>
  
  <p>I'm using ASP.Net Web Pages with Razor, edited with either WebMatrix or Visual Studio.  The code on the list page is simple.  The RefID is an integer Key uniquely identify the record:</p>
  
  <pre><code>var db = Database.Open("dbname");
  ...
  var q = db.Query( sqlthatworks , passInVarables);
  Session["WorkingList"] = q.Select( x =&gt; new { x.RefID } );
  </code></pre>
  
  <p>On the details page, I need to be able to access the Session["WorkingList"] such that I can use the Linq provided by this StackOverFLow question to  <a href="https://stackoverflow.com/questions/1333709/find-next-record-in-a-set-linq">find the next and previous records</a>, which will be something like:</p>
  
  <pre><code>var workingList = (IEnumerable&lt;dynamic&gt;) Session["WorkingList"];
  var nextRecord = workingList.SkipWhile(i =&gt; i.RefID != currentRecord).Skip(1).First();
  </code></pre>
  
  <p>I know that <a href="http://msdn.microsoft.com/en-us/library/webmatrix.data.database.query%28v=VS.99%29.aspx" rel="nofollow noreferrer">db.Query returns a IEnumerable&lt; Object></a>, but I'm guessing what's really coming back is a IEnumerable&lt; dynamic >.  And that works, but seems overly complicated.  Is there a better way?</p>