【发布时间】:2018-09-21 08:27:03
【问题描述】:
我有这个要求,它运作良好。主要问题是where filterIds.Contains(tags.UserTagId)部分。它会查找具有 OR 种类的所有标签。因此,如果我的 filterIds 值为 1、2、3,它会选择具有任何此标签的联系人。
var result = (from conts in _context.Contacts
where conts.CreatorUserId == _userManager.GetUserId(this.User) &&
(from tags in _context.ContactTags
where filterIds.Contains(tags.UserTagId)
select tags.ContactId).Contains(conts.ID)
select new
{
conts.ID, conts.Name, });
我需要找到所有具有 AND 类型的 ContactId。因此,如果联系人包含 ID 1、2 和 3,那就给我吧。就像找到所有具有所有这些标签的联系人一样。
from tags in _context.ContactTags
where filterIds[0] == tags.UserTagId
and filterIds[1] == tags.UserTagId
and filterIds[n] == tags.UserTagId
select ...
甚至
(from tags in _context.ContactTags
where filterIds[0] == tags.UserTagId
select ...) where filterIds[1] == tags.UserTagId ...
怎么做?
【问题讨论】:
-
使用两个 & 符号(不工作和)。
-
例外 - 为每个联系人单独请求 =(
-
我知道和 - 它只是一个示例 =)