Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to #16076 - Query: Nav rewrite type mismatch #16205

Closed
wants to merge 1 commit into from
Closed

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Jun 21, 2019

Problem was that when rewriting collection navigations into IQueryable, if the collection is composed on, we would always removing MaterializeCollectionNavigation. However, if the method was an instance method, e.g. List.ToArray, we should preserve the original collection type, so that the method call is still possible to make.
Fix is to look at the declaring type of instance method, and only strip MaterializeCollectionNavigation if the instance type is IQueryable.

@maumar maumar requested a review from smitpatel June 21, 2019 22:52
Problem was that when rewriting collection navigations into IQueryable, if the collection is composed on, we would always removing MaterializeCollectionNavigation. However, if the method was an instance method, e.g. List<T>.ToArray, we should preserve the original collection type, so that the method call is still possible to make.
Fix is to look at the declaring type of instance method, and only strip MaterializeCollectionNavigation if the instance type is IQueryable. For static methods, only remove MaterializeCollectionNavigation if the method is defined on Queryable or Enumerable
// for instance methods, make sure that the method caller is compatible with IQueryable
// otherwise, if we strip MaterializeCollectionNavigation we might no longer be able to construct the expression due to type mismatch
var newObject = Visit(methodCallExpression.Object);
if (methodCallerType != null && methodCallerType.IsQueryableType())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is all these other processing necessary?
Shouldn't it be as easy as, if it is a method on Queryable/Enumerable class then we strip off MaterializeCollectionNavigation. All other case, we leave it as is. In case if it was not necessary at some point (suppose some externally added method on IQueryable by provider), then at the translation time it can be handled easily.
p.s. Collection include can probably remove MaterializeCollectionNavigation too.

@smitpatel
Copy link
Member

Superseded by #16785

@smitpatel smitpatel closed this Jul 31, 2019
@smitpatel smitpatel deleted the fix16076 branch July 31, 2019 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants