2

在 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});

一切正常,但这不是解决方案。

4

2 回答 2

0
var recent = Repository.NewReads.Include("Book").Where(n => n.UserId == usersId).FirstOrDefault().Book.Select(b=>b.Authors);
于 2013-03-16T11:10:51.533 回答
0

你可以做

var recent = Repository.NewReads.Include(x => x.Book.Authors)
                       .Where(x => x.UserId == usersId);
于 2013-03-16T10:26:48.803 回答