<field name="value" value="A" />
<field name="value" value="B" />
<field name="text" value="C" />
<field name="text" value="D" />
<field name="key" value="E" />
When I filter I need to get one element for "value", one element for "text" and one element for "key" (Yes, "key" has only one element and it should be returned)
I tried
elements.Select(item=>item.Attribute("name")).Distinct();
This returns only the XAttribute but I need the entire XElement.
It sounds like you need DistinctBy
from MoreLINQ:
var distinct = elements.DistinctBy(x => x.Attribute("name").Value);
See more on this question at Stackoverflow