score:2

Something like this:

previous:

db.Set<Presentation>()
  .Where(x => x.Title < currentTitle)
  .OrderByDescending(x => x.Title)
  .FirstOrDefault()

next:

db.Set<Presentation>()
  .Where(x => x.Title > currentTitle)
  .OrderBy(x => x.Title)
  .FirstOrDefault()

score:0

You can also do it with one querry

            var myList = db.Set<Presentation>().OrderBy(x => x.Title ).ToList();

            int index = myList.FindIndex(a => a.Title == currentTitle);

            var previous = index > 1 ? myList[index - 1] : null;

            var next = index < myList.Count() ? myList[index + 1] : null;


Related Articles