gpt4 book ai didi

vb.net - LINQ 集合中的 Where 语句

转载 作者:行者123 更新时间:2023-12-04 23:27:43 25 4
gpt4 key购买 nike

我有一个包含 ContactNumbers 集合的 Customer 对象。
LINQ 是否可以获取其中一个联系号码 = '123' 的客户列表?

Public Class Customer
Public Overridable Property ContactNumbers As List(Of ContactNumber)

End Class

Public Class ContactNumber

<Required()>
Public Property ID As Integer

<Required()>
<StringLength(20)>
Public Property Number As String

Public Overridable Property Type As ContactNumberType

Public Property Primary As Boolean

End Class


Dim findnumber as String = '123'
Dim customers = db.customers.tolist

customers = customers.Where..... ?

最佳答案

尝试以下

customers = customers.Where(Function (x) x.ContactNumbers.Any(Function (y) y.Number = "123"))

这里的诀窍是 Any功能。这将返回 True如果集合中的任何项目与谓词匹配。在这种情况下 y.Number = 123

关于vb.net - LINQ 集合中的 Where 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9910568/

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