Question

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.

Was it helpful?

Solution

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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top