LINQ to get values from multi-value property of multiple objects
-
I have a class (simplified) such as
Public Class EquipmentRecord
Public Property Name as System.String
Public Property UpdateDate as System.DateTime
Public Property Parametrics as List(of Parametric)
End ClassFor this issue, doesn't matter what class Parametric is. I want to use LINQ to get all Parametrics from all EquipmentRecords where the UpdateDate is before a certain value. So...
Dim Records as List(of EquipmentRecord) = ... (gets a list with X number of objects)
Dim MatchParams as List(of Parametric) = (From ER As EquipmentRecord in Records ??????????????? WHERE ER.UpdateDate < DateToMatch).ToListBasically the "????????????" is where I'm lost. I have no idea how to select the multiple values from the Parametrics properties of multiple EquipmentRecords. Is it possible?
-
I have a class (simplified) such as
Public Class EquipmentRecord
Public Property Name as System.String
Public Property UpdateDate as System.DateTime
Public Property Parametrics as List(of Parametric)
End ClassFor this issue, doesn't matter what class Parametric is. I want to use LINQ to get all Parametrics from all EquipmentRecords where the UpdateDate is before a certain value. So...
Dim Records as List(of EquipmentRecord) = ... (gets a list with X number of objects)
Dim MatchParams as List(of Parametric) = (From ER As EquipmentRecord in Records ??????????????? WHERE ER.UpdateDate < DateToMatch).ToListBasically the "????????????" is where I'm lost. I have no idea how to select the multiple values from the Parametrics properties of multiple EquipmentRecords. Is it possible?
In C#,
List Records = (get list...)
List MatchParams = (from er in Records
from p in er.Parametrics
where er.UpdateDate < DateToMatch
select p).ToList();OR
List MatchParams2 = Records.Where(er => er.UpdateDate < DateToMatch).SelectMany(er => er.Parametrics).ToList();
Vince Remember the dead, fight for the living