Skip to content

Instantly share code, notes, and snippets.

@Programazing
Created October 9, 2016 02:48
Show Gist options
  • Save Programazing/a9712aa11001658bfdbc123b94666e8b to your computer and use it in GitHub Desktop.
Save Programazing/a9712aa11001658bfdbc123b94666e8b to your computer and use it in GitHub Desktop.
var book = (from theBook in _context.Books.Where(b => b.BookId == id)
join loan in _context.BookLoans.Where(x => !x.ReturnedOn.HasValue) on theBook.BookId equals loan.BookID into result
from loanWithDefault in result.DefaultIfEmpty()
select new BookDetailsViewModel
{
BookID = theBook.BookId,
SubTitle = theBook.SubTitle,
Title = theBook.Title,
Author = theBook.Author,
ISBN = theBook.ISBN,
GenreName = theBook.Genre.Name,
DeweyName = theBook.Dewey.Name,
StudentID = loanWithDefault.StudentID,
IsAvailable = loanWithDefault == null,
AvailableOn = loanWithDefault == null ? (DateTime?)null : loanWithDefault.DueOn
}).FirstOrDefault();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment