gpt4 book ai didi

c# - 查找不在数据表中但存在于 List 中的项目

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:05 25 4
gpt4 key购买 nike

我试图通过跨越 IEnumerable 数据行和自定义类之间的公共(public)字段来找到获取对象列表的方法。

我加载数据集并使用 DataSetExtensions 程序集将其转换为 IEnumerable Datarow()

  Dim listaRows = ds.Tables(0).AsEnumerable().Cast(Of DataRow).ToList()

然后我有一个自定义类列表,其中加载了可用于跨数据行字段的对象。

基本上,自定义类有一个名为 ParsedFileName 的属性这个项目存在在属性名称为 Filename 的数据行中.

我需要找出创建一个 linq 查询的方法,该查询发现列表中存在的元素(基于文件名字段)存在于可枚举数据行中。

我不能使用 List<T>.Except因为它接收的参数是同一类的第二个 Ienumerable 集合。

我一直在考虑如何查询,但我只设法得到这样的东西,它是无效的,因为它使用 equals not except。

我正在尝试这样的事情:

 Dim list As List(Of sftpClass.SftpObj) = _
listaFichero.Select(Function(l) Not l.FicheroParsed. _
Equals(listaRows.Select(Function(r) _
r.Field(Of String)("FICHERO")))).ToList

最佳答案

好吧,我终于用 HashSet 得到了它:

Dim listaRows = ds.Tables(0).AsEnumerable(). _
Cast(Of DataRow).ToList()

Dim valores = New HashSet(Of String) _
(listaRows.Select(Function(r) r.Field(Of String)("FICHERO")))

Dim query = _
listaFichero.Where(Function(l) _
Not valores.Contains(l.FicheroParsed)).ToList

关于c# - 查找不在数据表中但存在于 List<customclass> 中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19808929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com