首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何创建乘法哪里(和比较)与LINQ?

如何创建乘法哪里(和比较)与LINQ?
EN

Stack Overflow用户
提问于 2018-09-21 08:27:03
回答 1查看 89关注 0票数 0

我有这个要求,而且效果很好。主要问题是部分where filterIds.Contains(tags.UserTagId)。它查找带有 kind.So的所有标记,如果有1,2,3值的filterIds,则它选择具有此标记的联系人。

代码语言:javascript
复制
 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,那么就把它给我,就像查找所有有这些标签的联系人一样。

代码语言:javascript
复制
 from tags in _context.ContactTags
            where filterIds[0] == tags.UserTagId 
and filterIds[1] == tags.UserTagId 
and filterIds[n] == tags.UserTagId
            select ...

甚至是

代码语言:javascript
复制
 (from tags in _context.ContactTags
                where filterIds[0] == tags.UserTagId 

                select ...) where filterIds[1] == tags.UserTagId ...

怎么做?

EN

回答 1

Stack Overflow用户

发布于 2018-09-21 13:36:55

使用Count =查找解决方案(修改为Framwork )

代码语言:javascript
复制
 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...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52439617

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档