Question

I have an implementation of IQueryProvider and have the following method:

public override IQueryable<T> CreateQuery<T>(System.Linq.Expressions.Expression expression)
    {
        return new System.Linq.EnumerableQuery<T>(this.Items);
    }

The items property is defined as

public IEnumerable<T> Items { get; set; }

I get a cryptic compiler error for the EnumerableQuery constructor:

> Argument 1: cannot convert from
> 'System.Collections.Generic.IEnumerable<T>
> [c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll]' to
> 'System.Collections.Generic.IEnumerable<T>> [c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll]'

What am I doing wrong? I know it's likely to be wrapped up in the generics somewhere, but the arguments look the same to me!

Was it helpful?

Solution

The problem is your method declaration:

public override IQueryable<T> CreateQuery<T>(Expression expression)

You're declaring a new type parameter T in a generic method. That's not the same T as the type parameter for the type. Change it to be a non-generic method:

public override IQueryable<T> CreateQuery(Expression expression)

(As an aside, your code will be easier to use if you use appropriate using directives to avoid including so many fully-qualified type names in your code.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top