I think the full answer includes the previous answer, David Morton's comment, and an updated code snippet:
The .Where implementation for IQueryable is different from the .Where implementation for IEnumerable. IEnumerable.Where expects:
Func<XElement, bool> predicate
You can compile a function from an expression that you have:
Expression<Func<XElement, bool>> simpleXmlExpression = b => int.Parse(b.Element("FooId").Value) == 12; Func<XElement, bool> simpleXmlFunction = simpleXmlExpression.Compile(); var simpleXml = xml.Elements("Foo").Where(simpleXmlFunction).First();
This will allow you to view the generated expression tree and use the compiled form to query the xml collection.
source share