4

我知道我可以更改这样的查询

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

到拉姆达

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
4

1 回答 1

5

您正在寻找Select()方法:

.Select(Function(x) New TicketType With { ... })
于 2013-02-01T17:30:10.120 回答