我有一些看起来像这样的简单类:
Class Favorites
Guid UserId
Guid ObjectId
Class Objects
Guid Id
String Name
使用 Entity Framework,我想选择所有已被用户标记为收藏的对象。
所以我尝试了这样的事情
context.Objects.Where(
x => x.Id ==
context.Favorite.Where(f => f.UserId == UserId)
.Select(f => f.ObjectId).Any()
);
但是我不明白。我也尝试过相交,但我最了解的是同一类型。一个用户可以拥有多个收藏对象
最佳答案
你可以使用连接子句:
context.Favorite
.Where(f => f.UserId == UserId)
.Join(context.Objects, t => t.ObjectId, u => u.Id, (t, u) => t);
关于c# - Linq any - 如何选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13731107/