How to aggregate over few types with linq?

Posted by Shimmy on Stack Overflow See other posts from Stack Overflow or by Shimmy
Published on 2010-03-15T13:40:30Z Indexed on 2010/03/15 13:59 UTC
Read the original article Hit count: 465

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about aggregate