1

I write this method:

public List<TResult2> SelectAndJoin<TOuter, TInner, TKey, TResult, TResult2>(IEnumerable<TInner> inner, 
                                                                      System.Linq.Expressions.Expression<Func<Regions, TKey>> outerKeySelector, 
                                                                      System.Linq.Expressions.Expression<Func<TInner, TKey>> innerKeySelector, 
                                                                      System.Linq.Expressions.Expression<Func<Regions, TInner, TResult>> resultSelector,
                                                                      Func<Regions, TResult2> selector)
    {
        using (RepositoryDataContext = new DataClasses1DataContext())
        {
                return RepositoryDataContext.Regions.Join(inner, outerKeySelector, innerKeySelector, resultSelector).AsEnumerable<TResult2>().Select<Regions, TResult2>(selector).ToList<TResult2>();

        }
    }

but the expression follow return has this Error:

'System.Linq.IQueryable' does not contain a definition for 'AsEnumerable' and the best extension method overload 'System.Linq.Enumerable.AsEnumerable(System.Collections.Generic.IEnumerable)' has some invalid arguments

How I can get rid of this error?

is this code standard?

thanks

2 Answers 2

2

You're calling AsEnumerable<TResult2> on enumerable which will be of type IQueryable<TResult>. You should call AsEnumerable<TResult> or you can even omit generic parameter and call AsEnumerable()

Also your next select will not work for the same reason - you are providing wrong types for generics.

Sign up to request clarification or add additional context in comments.

Comments

0

I might be missing the point... but:

IQueryable inherits from IEnumerable so I think that AsEnumerable() is unnecessary in this code.

If you really do need/want to execute the query before doing the Select, then you could use ToList() instead of AsEnumerable() - this would be clearer

I'm also wondering if you are including using System.Linq in your .cs file - as AsEnumerable() is an extension method within System.Linq

3 Comments

AsEnumerable() is a neccessary step to be able to do Linq to Objects queries on top of a Linq to Entities/SQL query
This is not about using, he would have different error in that case.
I think the point is Join return a custom projection and it must be AsEnumerable<TResult>().I must test it and write here the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.