我有一个Customer对象,其中包含ContactNumbers的集合. 是否可以通过LINQ获取客户列表,其中一个联系号码=’123’? Public Class Customer Public Overridable Property ContactNumbers As List(Of ContactNumber)End Cla
是否可以通过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