views:

45

answers:

1
 Dim customers As List(Of Customer) = New List(Of Customer)
    For Each mbi In fordContracts
        customers.Add(mbi.Customer)
    Next

Is it possible to query fordContracts for customers? It is an IList(of mbi) and each mbi object has an EntityRef to a Customer object. I just wanted to know if there was a better way to achieve this using Linq.

Thanks.

+3  A: 

If you're adding to an existing list (which may have some elements already):

customers.AddRange(From mbi In fordContracts Select mbi.Customer)

If you want to get a brand new list:

customers = (From mbi In fordContracts Select mbi.Customer).ToList()
Pavel Minaev
Beautiful!!! This was exactly what I was looking for. Bravo!
Hcabnettek