GroupJoin and Include
本文关键字:Include and GroupJoin | 更新日期: 2023-09-27 18:04:06
GroupJoin之后我想包含Book。作者,因为田野的书。作者将为空。但是我不能。我该怎么做才能解决这个问题?
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});
I tried:
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});
你可以做
var recent = Repository.NewReads.Include(x => x.Book.Authors)
.Where(x => x.UserId == usersId);
var recent = Repository.NewReads.Include("Book").Where(n => n.UserId == usersId).FirstOrDefault().Book.Select(b=>b.Authors);