Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. public static string GetBooksByAuthor(BookShopContext context, string input)
  2. {
  3. StringBuilder sb = new StringBuilder();
  4.  
  5. var booksAndAuthors = context
  6. .Books
  7. .Where(b => b.Author.LastName.ToLower()
  8. .StartsWith(input, StringComparison.OrdinalIgnoreCase))
  9. .OrderBy(b => b.BookId)
  10. .Select(b => new
  11. {
  12. b.Title,
  13. Author = $"{b.Author.FirstName} {b.Author.LastName}"
  14. })
  15. .ToList();
  16.  
  17. foreach (var b in booksAndAuthors)
  18. {
  19. sb.AppendLine($"{b.Title} {b.Author}");
  20. }
  21.  
  22. return sb.ToString().TrimEnd();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement