Linq查询以过滤列表C#列表中的ID [英] Linq query to filter id inside a list of list c#

查看:82
本文介绍了Linq查询以过滤列表C#列表中的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结果列表的列表,其中包含列表中的List.我还有另一个列表,其中仅包含List.我想使用linq查询从数据中进行过滤,该数据应该返回包含技能ID的所有数据从第二个列表开始.

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

从第一个列表开始,它在技能列表中包含小数点列表; item.Skills包含列表,其中的字段是Skillid和代码. 项目是包含技能列表的另一个对象.

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.

推荐答案

如果skillId是变量,并假定SkillsList包含一个称为Id的属性.然后,以下操作将为您提供具有指定skillId的任何数据.

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

如果Skillslist只是一个整数数组,则可以使用以下内容.

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

这篇关于Linq查询以过滤列表C#列表中的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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