gpt4 book ai didi

c# - GroupJoin 和包含

转载 作者:太空宇宙 更新时间:2023-11-03 16:17:19 25 4
gpt4 key购买 nike

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

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

最佳答案

你可以做到

var recent = Repository.NewReads.Include(x => x.Book.Authors)
.Where(x => x.UserId == usersId);

关于c# - GroupJoin 和包含,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15447858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com