user2021740
user2021740

Reputation: 174

int[] array contains definition in linq query throw error

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>

Upvotes: 0

Views: 1903

Answers (1)

TGH
TGH

Reputation: 39278

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

List<int> ids = query;

Upvotes: 2

Related Questions