简体   繁体   English

Linq查询过滤列表中的id c#

[英]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. 我有一个结果列表列表,其中包含List里面的内容。我有另一个列表,其中只包含List。我想使用数据中的linq查询进行过滤,它应返回包含第二个数据的所有数据名单。

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.Skills包含字段为技能和代码的列表。 item is another object which contains the skillslist. item是另一个包含技能列表的对象。

if skillId is a variable and assuming that SkillsList contains a property called Id. 如果skillId是一个变量,并假设SkillsList包含一个名为Id的属性。 Then the following would work in getting you any data that has the specified skillId. 然后,以下内容可以帮助您获取具有指定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. 如果Skillslist只是一个整数数组,那么以下内容就可以了。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM