int[] 阵列在linq查询中包含定义,抛出错误[英] int[] array contains definition in linq query throw error

本文是小编为大家收集整理的关于int[] 阵列在linq查询中包含定义,抛出错误的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

var query = _db.Mst_Users
            .Where(item => item.CustomerUserId == customerUserId)
            .Traverse(item => _db.Mst_Users.Where(parent => item.CustomerUserId == parent.ParentId))
            .Select(item =>Convert.ToString(item.CustomerUserId)).ToArray();

在上面的查询中,我得到一个数组中的 customerUserIds:

int[] ids = query;

从上面的int数组:

var getgroup = from item in _db.Mst_Group 
               where ids.Contains(item.CustomerUserId) 
               select item;

但是,它显示以下错误:

int[] does not contain a definition for Contains and the best extension method overload system.linq.iqueryable.contains<tsource>

推荐答案

在第一个查询中尝试 ToList() 而不是 ToArray().它将返回一个包含"包含"方法的 List<int>

List<int> ids = query;

本文地址:https://www.itbaoku.cn/post/1557146.html

问题描述

var query = _db.Mst_Users
            .Where(item => item.CustomerUserId == customerUserId)
            .Traverse(item => _db.Mst_Users.Where(parent => item.CustomerUserId == parent.ParentId))
            .Select(item =>Convert.ToString(item.CustomerUserId)).ToArray();

In the above query I'm getting customerUserIds in an array:

int[] ids = query;

From the above int array:

var getgroup = from item in _db.Mst_Group 
               where ids.Contains(item.CustomerUserId) 
               select item;

However, it shows the following error:

int[] does not contain a definition for Contains and the best extension method overload system.linq.iqueryable.contains<tsource>

推荐答案

Try ToList() instead of ToArray() in the first query. It will return a List<int> that contains the "Contains" method

List<int> ids = query;