GroupJoin後,我想包括Book.Authors,因爲字段Book.Authors將爲空。 但我不能。我該怎麼做才能解決這個問題?Group加入幷包括
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});
所有工作正常,但它不是解決方案。
什麼LINQ提供您使用的呢? LINQ to SQL? LINQ to Entities?還有別的嗎? – svick 2013-03-16 15:20:58
很多人都說分組後形狀變化,都包括忽略。 – 2013-03-16 16:14:39
Linq to sql我認爲。因爲使用存儲庫,但不是DBContext。 – 2013-03-16 16:31:28