Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing Next/Previous with LINQ to SQL
    text
    copied!<p>I have the code below in an attempt to allow the user to "Step Through" the Case Notes in the DB by clicking Next or Previous on the WinForm. It will grab the First Case Note only. What am I doing wrong?</p> <p>There has been numerous edits to this post, I apologize, but in following Jon Skeet's advice I was able to "fix" what was originally wrong but it still doesn't work. </p> <p>Do I need to restructure my query to take into account the current note? If so, how do I do that?</p> <pre><code> public static Guid NextCaseNoteID (int personID) { var context = new MatrixDataContext(); Guid nextNoteID = (from caseNote in context.tblCaseNotes where caseNote.PersonID == personID orderby caseNote.InsertDate select caseNote.CaseNoteID ).Skip(1).FirstOrDefault(); return nextNoteID; } </code></pre> <hr> <hr> <p>This is what I ended up with, thanks to everyone who posted and followed my ill thought train of thought...</p> <p>It seems to work well though I am now trying to prove if I need the Skip(1) still.... Thanks!!</p> <p><em>for future reference</em></p> <pre><code> public static Guid NextCaseNoteID (int personID, DateTime? insertDate) { var context = new MatrixDataContext(); Guid nextNoteID = (from caseNote in context.tblCaseNotes where caseNote.PersonID == personID &amp;&amp; caseNote.InsertDate &gt; insertDate orderby caseNote.InsertDate select caseNote.CaseNoteID ).Skip(1).FirstOrDefault(); return nextNoteID; } public static Guid PreviousCaseNoteID(int personID, DateTime? insertDate) { var context = new MatrixDataContext(); Guid nextNoteID = (from caseNote in context.tblCaseNotes where caseNote.PersonID == personID &amp;&amp; caseNote.InsertDate &lt; insertDate orderby caseNote.InsertDate select caseNote.CaseNoteID).Skip(1).FirstOrDefault(); return nextNoteID; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload