У меня есть две таблицы, у автора может быть много книг, а у книги может быть только один автор.
public class Book
{
public int BookId { get; set; }
public string Title { get; set; }
public int Price { get; set; }
public int NumberOfPages { get; set; }
public DateTime PublishDate { get; set; }
public int AuthorId { get; set; }
public Author Author { get; set; }
}
public class Author
{
public int AuthorId { get; set; }
public string Name { get; set; }
public ICollection<Book> Books { get; set; }
}
В этом запросе я пытаюсь получить автора с соответствующими книгами. , Я не знаю, правильный ли запрос, но я получаю следующую ошибку:
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.
public IQueryable<Authors> Filter()
{
var authors = from a in db.Authors
join b in db.Books on a.AuthorsId equals b.AuthorsId
select new Authors { AuthorsId = a.AuthorsId, Name = a.Name, Books = a.Books};
return authors;
}