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. GridView using LINQ

GridView using LINQ

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqxmlhelp
3 Posts 2 Posters 2 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.
  • I Offline
    I Offline
    Illegal Operation
    wrote on last edited by
    #1

    Please help! I am running a LINQ query against an existing XML file that looks like this: public object GetByCaseId() { XDocument xmlDocument = XDocument.Load(@"c:\test.xml"); var queryUsername = from Case in xmlDocument.Descendants("Case") where Case.Attribute("CaseId").Value == userName.ToString() select new { CaseId = Case.Attribute("CaseId").Value, CaseManager = Case.Attribute("CaseManager").Value, NoteCreated = Case.Element("Note").Attribute("NoteCreated").Value, NoteContent = Case.Element("Note").Attribute("NoteContent").Value }; gridViewer = queryUsername; return gridViewer; } The Query works fine but there are multiple notes per case and it only brings back the first note of each case. For every CaseId, CaseManager I need to bring back multiple Notes. Thank you!!!

    Illegal Operation

    H 1 Reply Last reply
    0
    • I Illegal Operation

      Please help! I am running a LINQ query against an existing XML file that looks like this: public object GetByCaseId() { XDocument xmlDocument = XDocument.Load(@"c:\test.xml"); var queryUsername = from Case in xmlDocument.Descendants("Case") where Case.Attribute("CaseId").Value == userName.ToString() select new { CaseId = Case.Attribute("CaseId").Value, CaseManager = Case.Attribute("CaseManager").Value, NoteCreated = Case.Element("Note").Attribute("NoteCreated").Value, NoteContent = Case.Element("Note").Attribute("NoteContent").Value }; gridViewer = queryUsername; return gridViewer; } The Query works fine but there are multiple notes per case and it only brings back the first note of each case. For every CaseId, CaseManager I need to bring back multiple Notes. Thank you!!!

      Illegal Operation

      H Offline
      H Offline
      Howard Richards
      wrote on last edited by
      #2

      It's returning just the first element because that's effectively what Case.Element() is doing. I assume you want to flatten the heirarchy, to get:

      CaseId CaseManager NoteCreated NoteContent
      AAA BBB date Note1
      AAA BBB date Note2

      where CaseID AAA has two notes. Try querying on the Notes and using the Ancestors for the filter..

      var qry = from Note in doc.Descendants("Note")
      where Note.Ancestors("Case").First().Attribute("CaseId").Value == userName
      select new
      {
      CaseId = Note.Ancestors("Case").First().Attribute("CaseId").Value,
      CaseManager = Note.Ancestors("Case").First().Attribute("CaseManager").Value,
      NoteCreated = Note.Attribute("NoteCreated").Value,
      NoteContent = Note.Attribute("NoteContent").Value
      };

      'Howard

      I 1 Reply Last reply
      0
      • H Howard Richards

        It's returning just the first element because that's effectively what Case.Element() is doing. I assume you want to flatten the heirarchy, to get:

        CaseId CaseManager NoteCreated NoteContent
        AAA BBB date Note1
        AAA BBB date Note2

        where CaseID AAA has two notes. Try querying on the Notes and using the Ancestors for the filter..

        var qry = from Note in doc.Descendants("Note")
        where Note.Ancestors("Case").First().Attribute("CaseId").Value == userName
        select new
        {
        CaseId = Note.Ancestors("Case").First().Attribute("CaseId").Value,
        CaseManager = Note.Ancestors("Case").First().Attribute("CaseManager").Value,
        NoteCreated = Note.Attribute("NoteCreated").Value,
        NoteContent = Note.Attribute("NoteContent").Value
        };

        'Howard

        I Offline
        I Offline
        Illegal Operation
        wrote on last edited by
        #3

        Thank you Howard!! You gave me exactly what I was looking for. I have implemented it and it works!! I very much Appreciate it!!

        Illegal Operation

        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