VB.NET LINQ Where子句集合中如何高效筛选数据?
- 内容介绍
- 文章标签
- 相关推荐
本文共计193个文字,预计阅读时间需要1分钟。
我有一个个Customer对象,其中包含ContactNumbers的集合。是否可以通过LINQ获取客户列表,其中某个联系电话号码=123?
我有一个Customer对象,其中包含ContactNumbers的集合.是否可以通过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
本文共计193个文字,预计阅读时间需要1分钟。
我有一个个Customer对象,其中包含ContactNumbers的集合。是否可以通过LINQ获取客户列表,其中某个联系电话号码=123?
我有一个Customer对象,其中包含ContactNumbers的集合.是否可以通过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

