int []数组包含linq查询抛出错误中的定义 [英] int[] array contains definition in linq query throw error

查看:62
本文介绍了int []数组包含linq查询抛出错误中的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();

在上面的查询中,我在数组中获取了customerUserId:

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

int[] ids = query;

从上面的int数组:

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>

推荐答案

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

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

List<int> ids = query;

这篇关于int []数组包含linq查询抛出错误中的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆