Using LINQ Group By to return new XElements?

X, per iteration, is the sequence of elements (excluding the first one). I suspect you want: from grp in f from x in grp let sequenceNumber = x. Element("DOCUMENTID").

Value Although you could also bring the group-key out in the projection if you wanted, by simplifying further: var f = (from x in MyDocument. Descendants("RECORD") where itemsThatWasDuplicated. Contains((int)x.

Element("DOCUMENTID")) group x by x. Element("DOCUMENTID"). Value); var errorQuery = (from grp in f from x in grp.

Skip(1) let detail = "Sequence number " + grp. Key + " was read more than once.

X, per iteration, is the sequence of elements (excluding the first one). I suspect you want: from grp in f from x in grp let sequenceNumber = x. Element("DOCUMENTID").

Value //... Although you could also bring the group-key out in the projection if you wanted, by simplifying further: var f = (from x in MyDocument. Descendants("RECORD") where itemsThatWasDuplicated. Contains((int)x.

Element("DOCUMENTID")) group x by x. Element("DOCUMENTID"). Value); var errorQuery = (from grp in f from x in grp.

Skip(1) let detail = "Sequence number " + grp. Key + " was read more than once" //...

I have managed to get this to compile and seems to work but maybe there are some performance tweaks needed or I'm doing something inefficient. What do you think? ErrorQuery = MyDocument.

Descendants("RECORD") . Where(x => itemsThatWasDuplicated. Contains((int)x.

Element("DOCUMENTID"))) . GroupBy(a => a. Element("DOCUMENTID"), (innerID, values) => values.

OrderBy(b => b. Element("ID"). Value)) .

Skip(1) . SelectMany(p => p) . Select(item => new XElement("ERROR", new XElement("DATETIME", time), new XElement("DETAIL", "Sequence number " + item.

Element("DOCUMENTID"). Value + " was read more than once"), new XAttribute("TYPE", "DUP"), new XElement("ID", item. Element("ID").

Value) )).

GroupBy(a => a. Element("DOCUMENTID"), (innerID, values) => values. OrderBy(b => b.

New XElement("DETAIL", "Sequence number " + item. New XElement("ID", item.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions