I have an object class that contains information about anchors and down guy wires and create a list of those objects.
Public Class AnchorsAndDownGuysInformation
Public Sub New(ByVal aCoordX As String,
ByVal aCoordA As String,
ByVal dDesc As String,
ByVal dCoordZ As String,
ByVal dDiameter As String,
ByVal dRtsStrength As String,
ByVal dPoundsPerInch As String)
CoordXAnchor = aCoordX
CoordAAnchor = aCoordA
Description = dDesc
CoordZDown = dCoordZ
Diameter = dDiameter
RTSStrength = dRtsStrength
PoundsPerInch = dPoundsPerInch
End Sub
Public Property CoordXAnchor As String
Public Property CoordAAnchor As String
Public Property Description As String
Public Property CoordZDown As String
Public Property Diameter As String
Public Property RTSStrength As String
Public Property PoundsPerInch As String
End Class
For example sake, lets say there are four items in the list of AnchorsAndDownGuysInformation. Two of them have the same CoordXAnchor and CoordAAnchor. I need to group them by those values and send them to another class Anchors which references the Downguys class.
Public Class Anchors
Public Property CoordXAnchor As String
Public Property CoordAAnchor As String
Public Property DownGuyInfo As New List(Of DownGuys)
End Class
Public Class DownGuys
Public Property Description As String
Public Property CoordZDown As String
Public Property Diameter As String
Public Property RTSStrength As String
Public Property PoundsPerInch As String
End Class
So the final result would be a list of Anchor Class; three (3) anchors, one (1) with two (2) DownGuys and two (2) anchors with one (1) DownGuy each.
I have tried a few things but cant seem to get it to work.
Dim groupedAnchors = anchorsAndDownGuyList.GroupBy(Function(x) New With {x.CoordAAnchor, x.CoordXAnchor
}).[Select](Function(anc) New Anchors() With {
.CoordAAnchor = anc.Key.CoordAAnchor,
.CoordXAnchor = anc.Key.CoordXAnchor,
.DownGuyInfo = anc.[Select](Function(dg) New DownGuys() With {
.Description = dg.Description,
.CoordZDown = dg.CoordZDown,
.Diameter = dg.Diameter,
.RTSStrength = dg.RTSStrength,
.PoundsPerInch = dg.PoundsPerInch
})})
I cant seem to get this to work...
I have also tried just grouping them and then trying to send them to the class after the grouping. A two step approach. I can get them grouped but cant seem to access the data afterwards to then send to the class.
What I have tried....
Dim groupedAnchors = anchorsAndDownGuyList.GroupBy(Function(j) New With {Key j.CoordAAnchor, Key j.CoordXAnchor}).
Select(Function(group) group.Key.CoordAAnchor).ToList()
Dim groupedAnchors2 = anchorsAndDownGuyList.GroupBy(Function(a) New With {Key a.CoordAAnchor, Key a.CoordXAnchor}).ToList()
I hope I explained myself well and someone can help me out. Thank you in advance.