C# Linq Select Problem in Method Chain.

Posted by Gnought on Stack Overflow See other posts from Stack Overflow or by Gnought
Published on 2010-03-16T08:50:44Z Indexed on 2010/03/16 8:56 UTC
Read the original article Hit count: 181

Filed under:
|
|
|

Note that the _src inherit IQueryable<U> and V inherit new();

I wrote the following statement, there is no syntax error.

IQueryable<V> a = from s in _src where (s.Right - 1 == s.Left) select new V();

But if i re-wrote it as follows, the Visual Studio editor complains an error in the "Select"

IQueryable<V> d = _src.Where(s => s.Right - 1 == s.Left).Select(s=> new V());

The Error is:

The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly.
Candidates are:
  System.Collections.Generic.IEnumerable<V> Select<U,V>(this System.Collections.Generic.IEnumerable<U>, System.Func<U,V>) (in class Enumerable)
  System.Linq.IQueryable<V> Select<U,V>(this System.Linq.IQueryable<U>, System.Linq.Expressions.Expression<System.Func<U,V>>) (in class Queryable)

Could anyone explain this phenomenon, and what the solution is to fix the error?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ