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?
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.
Do I need to restructure my query to take into account the current note? If so, how do I do that?
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;
}
This is what I ended up with, thanks to everyone who posted and followed my ill thought train of thought...
It seems to work well though I am now trying to prove if I need the Skip(1) still.... Thanks!!
for future reference
public static Guid NextCaseNoteID (int personID, DateTime? insertDate)
{
var context = new MatrixDataContext();
Guid nextNoteID = (from caseNote in context.tblCaseNotes
where caseNote.PersonID == personID && caseNote.InsertDate > 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 && caseNote.InsertDate < insertDate
orderby caseNote.InsertDate
select caseNote.CaseNoteID).Skip(1).FirstOrDefault();
return nextNoteID;
}