I have this request, and it works well. The main point of question is part where filterIds.Contains(tags.UserTagId)
. It looks for all tags with OR kind.So if I have filterIds with 1,2,3 value it selects contact that have any of this tag.
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, });
I need to find all ContactId with AND kind. So if contact contains Ids 1, and 2 and 3 - so give it to me.It's like find all contacts that have ALL of this tags.
from tags in _context.ContactTags
where filterIds[0] == tags.UserTagId
and filterIds[1] == tags.UserTagId
and filterIds[n] == tags.UserTagId
select ...
or even
(from tags in _context.ContactTags
where filterIds[0] == tags.UserTagId
select ...) where filterIds[1] == tags.UserTagId ...
How to do that?