我有下面的代码,试图让用户通过单击WinForm上的Next或Previous来在数据库中“浏览”Case Notes。它只会抓住第一个案例笔记。 我在做什么错?使用LINQ to SQL实现Next/Previous使用LINQ to SQL
对这篇文章进行了大量修改,我很抱歉,但在遵循Jon Skeet的建议之后,我能够“修复”原本错误的内容,但仍然无法正常工作。
我是否需要重构我的查询以考虑当前注释?如果是这样,我该怎么做?
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;
}
这是我结束了,感谢大家谁张贴,随后想起了生病想到火车...
看来,虽然我现在的工作很好试图证明,如果我需要跳过(1)仍然.... 谢谢!
以供将来参考
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;
}
你为什么要返回分辨率而不仅仅是guid? –
Geoff
2009-08-20 19:17:18
@Geoff:Resharper告诉我,我没有(没有)知道更好。在Jon Skeet的帖子下看到我的评论。 – 2009-08-20 19:19:52
根据您的编辑,您是否可以确认caseNote.CaseNoteID返回的内容实际上是32位数,并且有4个破折号? – Geoff 2009-08-20 19:32:50