I am having a bear of a time getting this to work. I have a List(Of MyItem)
called Items
that have a OrderId
property on them. From those items, I want to create a list of Order
s. Some items will have the same OrderId
so I want to try to group by OrderId
. I then want to sort by date. Here's what I have so far:
Public ReadOnly Property AllOrders() As List(Of Order)
Get
Return Items.Select(Function(i As MyItem) New Order(i.OrderID)) _
.GroupBy(Function(o As Order) New Order(o.OrderID)) _
.OrderBy(Function(o As Order) o.DateOrdered).ToList
End Get
End Property
This, of course, doesn't compile, and I get the error:
Value of type 'System.Collections.Generic.List(Of System.Linq.IGrouping(Of Order, Order))' cannot be converted to 'System.Collections.Generic.List(Of Order))'
I've bolded the part where I think the problem is, but I have no idea how to fix it. Also, it used to work fine (except there were duplicate values) before I added the .GroupBy
statement. Anyone have any ideas?
Thanks
EDIT
Basically, I want this:
List of Existing Items Take List and Turn it into List(Of MyItem): List(Of Order): ItemId OrderId OrderID 1 100 100 2 102 102 3 100