Last Updated:
22 Nov 2021 10:28
by ADMIN
GridView: TargetInvocationException is thrown when IQueryable is used and grouping is applied
The exception occurs when DBSet<T> is used with a Select query that creates new objects of type that is not included in the EDMX model. The issue appears because the internally used IQueryableCollectionView calls OfType<T>() on the IQueryable which is not allowed in the specific setup.
The exception is the following: "TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: 'WpfApp4.MainWindow+MyClass'is not a valid metadata type for type filtering operations. Type filtering is only valid on entity types and complex types."
To work this around, you can call ToList() over the IQueryable object before pass it to RadGridView's ItemsSource.