我有这个要求,而且效果很好。主要问题是部分where filterIds.Contains(tags.UserTagId)。它查找带有或 kind.So的所有标记,如果有1,2,3值的filterIds,则它选择具有此标记的联系人。
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, });我需要找到所有的ContactId与和类。所以如果联系人包含Ids 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 ...怎么做?
发布于 2018-09-21 13:36:55
使用Count =查找解决方案(修改为Framwork )
var result = _context.Contacts.Where(conts => conts.CreatorUserId == _userManager.GetUserId(this.User)
&& conts.Tags.Where(t => filterIds.Contains(t.UserTagId)).Count() == filterIds.Count)
.Select(conts=> new...https://stackoverflow.com/questions/52439617
复制相似问题