How to aggregate over few types with linq?
- by Shimmy
Can someone help me translate the following to one liner:
Dim items As New List(Of Object)
For Each c In ph.Contacts
items.Add(New With {.Type = "Contact", .Id = c.ContactId, .Title = c.Title})
Next
For Each c In ph.Persons
items.Add(New With {.Type = "Person", .Id = c.PersonId, .Title = c.Title})
Next
For Each c In ph.Jobs
items.Add(New With {.Type = "Job", .Id = c.JobId, .Title = c.Title})
Next
Is it possible to merge them all into one query or method line, I don't really care if this will be done with something other than linq, I am just looking for a more efficient way as I have a long list coming ahead, and the aggregating list will be strongly-typed using Dim list = blah blah