Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq query to filter id inside a list of list c#

I have a list of result List where it contains List inside of it.I have another list where it contains List alone.I want to filter using a linq query from the data where it should return all the data which contains skill id from the second list.

var list = this._viewModel.Data.Select(T => T.SkillsList);
var filtered = item.Skills.Contains(list.Where(t=>t.ToString()).ToList();

from the first list it contains List of decimals inside the skill list; item.Skills contains list where the fields are skillid and code. item is another object which contains the skillslist.

like image 374
Sajeetharan Avatar asked Aug 14 '13 04:08

Sajeetharan


1 Answers

if skillId is a variable and assuming that SkillsList contains a property called Id. Then the following would work in getting you any data that has the specified skillId.

var list = this._viewModel.Data.Where(t=>t.SkillsList.Any(s=>s.Id == skillId));

If Skillslist is just an array of integers then the following would work.

var list = this._viewModel.Data.Where(t=>t.SkillsList.Any(s=> s == skillId));

Now if you are checking against a list the following would work.

var list = this._viewModel.Data.Where(t=>t.SkillsList.Any(s=> skillsList.contains(s));
like image 130
nerdybeardo Avatar answered Oct 27 '22 13:10

nerdybeardo