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