在 GroupJoin 之后,我想包含 Book.Authors,因为 Book.Authors 字段将为空。但我不能。我应该怎么做才能解决这个问题?
Queryable<NewRead> recent = Repository.NewReads.Where(x => x.UserId == usersId);
var newFavs = IsAuthorized ? Repository.NewFavs.Where(x => x.UserId == UserId) : Repository.NewFavs.Where(x => false);
var recentFavorite = recent.GroupJoin(newFavs,
x => x.BookId,
y => y.BookId,
(x, y) => new {Recent = x, Favorite = y, x.Book});
我试过了:
var recent = Repository.NewReads.Include("Book.Authors")
.Where(x => x.UserId == usersId);
和
var newFavs = IsAuthorized ? Repository.NewFavs.Include("Book.Authors").Where(x => x.UserId == UserId) : Repository.NewFavs.Where(x => false);
以及所有这一切。它在 GroupJoin 之前有效,但在 Authors 字段丢失之后。如果我添加:
var recentFavorite = recent.GroupJoin(newFavs,
x => x.BookId,
y => y.BookId,
(x, y) => new {Recent = x, Favorite = y, x.Book, x.Book.Authors});
一切正常,但这不是解决方案。