Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 673137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:33:45+00:00 2026-05-14T00:33:45+00:00

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

  • 0

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?

=== Edit (2010-03-16 5:35pm) ===

Thanks Mike Two. I also tried a simple example like you. It works but this does not do in mine. I posted the code as follows:

public class NSM<U, V> where U : IQueryable<U> where V : new()  
  {
    private U _src;
    public NSM(U source) { _src = source; }
    public IQueryable<V> LeafNodes
    {
      get
        {
          return from s in _src where (s.Right - 1 == s.Left) select new V();
        }
    }
  }

I want the LeafNodes function to be rewritten into linq method chain method. Any Idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:33:45+00:00Added an answer on May 14, 2026 at 12:33 am

    What is the type of _src? Does it directly implement IQueryable? I ask because I can get a simplified example of what you are showing to work.

    IQueryable< int > ints = Enumerable.Range( 4, 12 ).AsQueryable();
    
    IQueryable< decimal > foo = from s in ints where s > 7 select s * 4.2m;
    
    IQueryable< decimal > bar = ints.Where( s => s > 7 ).Select( s => s * 4.2m );
    

    Both of those selects work for me. I think if the compiler knows that ints (or in your case _src) is an IQueryable then it will call the right overload. Or am I completely missing something? Perhaps I oversimplified it and lost a bit of detail.

    EDIT: Extending this to use the new sample code with some changes.

    The trick is that Queryable.Select takes an Expression<Func<X, V>> and Enumerable.Select takes a Func<X,V> So you just need to provide an Expression version to Select

    public interface ILeftRight
    {
        int Right { get;}
        int Left { get; }
    }
    
    public class NSM<X, U, V> where U : IQueryable<X> where X : ILeftRight where V : new()  
    {
        private readonly U _src;
        public NSM(U source) { _src = source; }
        public IQueryable<V> LeafNodes
        {
            get
            {
                //return from s in _src where (s.Right - 1 == s.Left) select new V();
                Expression< Func< X, V > > expression = s => new V();
                return _src.Where( s => s.Right - 1 == s.Left ).Select( expression );
            }
        }
    }
    

    Or from the original code

    Expression<Func<X,V>> expression = s => new V();
    IQueryable<V> d = _src.Where(s => s.Right - 1 == s.Left).Select(expression);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[Please note that this is a different question from the already answered How to
(note that this question is not about CAS, it's about the May fail spuriously
Note that I'm aware of other yield in vb.net questions here on SO. I'm
Note that all the code is a simplified example in order to only communicate
Note that this is for an ApiController in MVC 4 although I think it
Warning: Note that this is a dumb question of something that I would probably
Edit : Note that, as Daniel and latkin noted in an answer and a
Please note that I'm not asking how but why. And I don't know if
(Please note that I have seen a similar question on StackOverflow recently, however I
EDIT: Note that due to the way hard drives actually write data, none of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.