This is because Descendants(XName name) returns an IEnumerable<XElement> .
By design, IEnumerable lazy loads data, and so counting items in a collection will result in an enumeration.
I would probably convert it to an IList that has a Count property that you can use.
source share