【发布时间】:2012-05-08 19:58:10
【问题描述】:
我的表使用多对多关系。
有一个查询:
var query = from post in context.Posts
from tag in post.Tags where tag.TagId == 10
select post;
好的,它工作正常。我收到带有 id 指定标签的帖子。
我有一组标签 ID。而且我想获得包含我收藏中每个标签的帖子。
我尝试以下方式:
var tagIds = new int[]{1, 3, 7, 23, 56};
var query = from post in context.Posts
from tag in post.Tags where tagIds.Contains( tag.TagId )
select post;
它不起作用。该查询返回具有任何一个指定标签的所有帖子。
我想得到一个这样的子句,但动态地用于集合中任何数量的标签:
post.Tags.Whare(x => x.TagId = 1 && x.TagId = 3 && x.TagId = 7 && ... )
【问题讨论】:
标签: c# linq entity-framework-4 dbcontext