Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. LINQ to get values from multi-value property of multiple objects

LINQ to get values from multi-value property of multiple objects

Scheduled Pinned Locked Moved LINQ
csharplinqhelptutorialquestion
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PSU Steve
    wrote on last edited by
    #1

    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 Class

    For 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).ToList

    Basically 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?

    V 1 Reply Last reply
    0
    • P PSU Steve

      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 Class

      For 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).ToList

      Basically 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?

      V Offline
      V Offline
      Vincent Blais
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups