C# LINQ Where Predicate Type Arguments

Posted by blu on Stack Overflow See other posts from Stack Overflow or by blu
Published on 2009-02-09T18:07:17Z Indexed on 2010/05/23 18:00 UTC
Read the original article Hit count: 316

I have an XElement with values for mock data.

I have an expression to query the xml:

Expression<Func<XElement, bool>> simpleXmlFunction = 
    b => int.Parse(b.Element("FooId").Value) == 12;

used in:

var simpleXml = xml.Elements("Foo").Where(simpleXmlFunction).First();

The design time error is:

The type arguments for method 'System.Linq.Enumerable.Where(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly'

The delegate supplied to Where should take in an XElement and return a bool, marking if the item matches the query, I am not sure how to add anything more to the delegate or the where clause to mark the type.

Also, the parallel method for the real function against the Entity Framework does not have this issue. What is not correct with the LINQ-to-XML version?

© Stack Overflow or respective owner

Related posts about c#

Related posts about entity-framework