Issue in non Generic Execute Method in DbLinq.Data.Linq.Implementation.QueryProvider

by Carlos Mendible on 19 Oct 2009 » dotNet

We’ve been working with DbLinq for a while now, at HexaSystems and recently using it together with Dynamic Linq and SQLite I programed a call to the Count method of a Queryable object as follows:

public static int Count(this IQueryable source)
    if (source == null) throw new ArgumentNullException("source");

    return (int)source.Provider.Execute(
            new Type[] { source.ElementType },

I noticed that when doing so against a DbLInq Table object the following method is called:

public object Execute(Expression expression)

The problem is that the function calls the generic Execute method inside the same class with the generic argument of type object: “Execute(expression)” which causes an invalid cast exception in the case I’m talking about, and potentially any call to this method could fail when the expression evaluation creates a generic type. I’ve submitted a patch to DBLinq developers and it was offically accepted: