This is a migrated thread and some comments may be shown as answers.

[Solved] Cannot set aggregates on LinqKit queries (because of function Provider.IsEntityFrameworkProvider())

0 Answers 4 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
mbp
Top achievements
Rank 1
mbp asked on 02 May 2013, 11:13 AM
Dear all,

When I use a LinqKit query in a telerik grid, I cannot add aggregates, I get this error message:
Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to Entities only supports casting Entity Data Model primitive types.

After some debugging I found that the problem is the function CreateKeyMemberBinding(), which contains
            // Our Key property is of type object so we need to box if the value is ValueType.
            // EF did not support convert so did not call it.
            // Note: We can fix all this if our group is generic type similar to IGrouping<TKey, TElement>
            if (keyPropertyExpression.Type.IsValueType &&
                !this.Queryable.Provider.IsEntityFrameworkProvider())
            {
                keyPropertyExpression = Expression.Convert(keyPropertyExpression, typeof(object));
            }

And the function         public static bool IsEntityFrameworkProvider(this IQueryProvider provider)
        {
            return provider.GetType().FullName == "System.Data.Objects.ELinq.ObjectQueryProvider" ||
                provider.GetType().FullName.StartsWith("System.Data.Entity.Internal.Linq");
        }


As LinqKit has an another provider name, it is not recognized as an entityframework provider while it is an entity framework provider, it is just an extension to the regular provider.
How can I solve this problem without having to modify the sources of Telerik Grid ?

Thank you in advance.

Tags
Grid
Asked by
mbp
Top achievements
Rank 1
Share this question
or