当前位置 : 主页 > 编程语言 > c语言 >

VB.Net Lambda查询

来源:互联网 收集:自由互联 发布时间:2021-06-24
我知道我可以改变这样的查询 Dim myList As List(Of Tickets) = (From a In db.myTable Where a.ID = id AndAlso a.IsOnline = True).ToList 到lambda Dim myList as List(of Tickets) = db.Where(Function(x) x.ID = id ANDAlso a.IsOnline =
我知道我可以改变这样的查询

Dim myList As List(Of Tickets) = (From a In db.myTable
                  Where a.ID = id AndAlso a.IsOnline = True).ToList

到lambda

Dim myList as List(of Tickets) = db.Where(Function(x) x.ID = id ANDAlso a.IsOnline = true).ToList

我如何编写lambda版本并告诉它用结果创建一个新对象?像这样:

Dim myList As List(Of Tickets) = (From a In db.myTable
                             Where a.ID = id AndAlso a.IsOnline = True
                             Select New TicketType With {
                                       .Id = a.rsID.ToString,
                                       .Title = a.rsTitle}).ToList
您正在寻找Select()方法:

.Select(Function(x) New TicketType With { ... })
网友评论