In the following example in Entity Framework, how to find the author of a specified book using linq:
public class Author
{
public int Id { get; set; }
public string AuthorName { get; set; }
public ICollection<Book> Books { get; set; }
}
public class Book
{
public int Id { get; set; }
public int Title { get; set; }
}
Thanks.
Assuming you have a collection of authors, you would simply do
var author = authors.SingleOrDefault(x=> x.Books.Any(y=> y.Title.Equals(bookTitle, StringComparison.OrdinalIgnoreCase))
This assumes that books have only one author.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With