Skip to content

Fix using a loaded IPersistentCollection in a Query #1560

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

Merged
merged 2 commits into from
Jan 29, 2018

Conversation

gliljas
Copy link
Member

@gliljas gliljas commented Jan 26, 2018

Fixes #1556

The problem was that the IPersistentCollection now implement IQueryable, which the PartialEvaluatingExpressionVisitor always rewrites to its inner expression. I could find no way to intercept this mechanism, except to clone the entire class from source and rewrite it according to our needs. Relinq is licensed under Apache 2.0, so that should not be an issue.

@gliljas gliljas force-pushed the GH-1556 branch 2 times, most recently from d67255f to f5bc175 Compare January 26, 2018 23:30
using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation;

namespace NHibernate.Linq.Visitors
{
//Modified version of PartialEvaluatingExpressionVisitor from Relinq (https://github.com/re-motion/Relinq)
//Copyright (c) rubicon IT GmbH, www.rubicon.eu
Copy link
Member

Choose a reason for hiding this comment

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

According to https://tldrlegal.com/license/apache-license-2.0-(apache-2.0) we must include the license. So, I think it shall be included on the top of the file.

Copy link
Member

Choose a reason for hiding this comment

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

I think lines differing from original implementation should be signaled by comments, for easing seeing what is done differently in NHibernate.

{
return EvaluateIndependentSubtrees(expression, new NhEvaluatableExpressionFilter());
}
/// <summary>
Copy link
Member

Choose a reason for hiding this comment

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

Better have a blank line between methods.

using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation;

namespace NHibernate.Linq.Visitors
{
//Modified version of PartialEvaluatingExpressionVisitor from Relinq (https://github.com/re-motion/Relinq)
//Copyright (c) rubicon IT GmbH, www.rubicon.eu
Copy link
Member

Choose a reason for hiding this comment

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

I think lines differing from original implementation should be signaled by comments, for easing seeing what is done differently in NHibernate.

var constantExpression = (ConstantExpression) subtree;
var valueAsIQueryable = constantExpression.Value as IQueryable;
if (valueAsIQueryable != null && !IsEvaluatedQueryable(constantExpression.Value) && valueAsIQueryable.Expression != constantExpression)
return valueAsIQueryable.Expression;
Copy link
Member

Choose a reason for hiding this comment

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

I guess this is here that code differs. It seems to create a bunch of test failures, but I have not tried analyzing them yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll have a look.

@@ -35,6 +124,8 @@ public Expression VisitPartialEvaluationException(PartialEvaluationExceptionExpr
}
}



Copy link
Member

Choose a reason for hiding this comment

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

Undue additional blank lines.

@gliljas gliljas force-pushed the GH-1556 branch 2 times, most recently from d67b1ec to b0d63a6 Compare January 28, 2018 12:34
@gliljas
Copy link
Member Author

gliljas commented Jan 28, 2018

Interesting test errors on a couple of DB types. Investigating.

@hazzik
Copy link
Member

hazzik commented Jan 28, 2018

The simplest fix is to extend filter to mark this type of collection as not enumerable.

@hazzik hazzik added this to the 5.1 milestone Jan 28, 2018
@hazzik hazzik changed the title Fix for GH-1556 - Use a loaded IPersistentCollection in a Query Fix using a loaded IPersistentCollection in a Query Jan 28, 2018
@hazzik
Copy link
Member

hazzik commented Jan 29, 2018

An interesting side effect of this change is that operations on IPersistenceCollection + IQueryable are executed on server side (embedded as a sub-query) as opposite being included as a parameter list.

EDIT: I was wrong.

@gliljas
Copy link
Member Author

gliljas commented Jan 29, 2018

@hazzik That's a bad side effect.

@gliljas
Copy link
Member Author

gliljas commented Jan 29, 2018

Also, I'm all for LGTM, but I'd prefer a heads up rather than an edit.

@hazzik
Copy link
Member

hazzik commented Jan 29, 2018

I’ll double check, but I’m pretty sure that your original changes had the same side effect.

The code change is trivial, so it was easier to check-in, because to verify my assumption I had to make this change.

@hazzik
Copy link
Member

hazzik commented Jan 29, 2018

@gliljas, actually, I was wrong (it seems that I'm blind / was dreaming). The both cases produce exactly the same query. They do not inline the collection into the query, but rather use the in (@p1, ...) expression.

@fredericDelaporte
Copy link
Member

For proper attribution it would be better if this PR is squashed/merged by Alexander. If I squash/merge it myself only Gunnar and me would appear on the master commit.

@hazzik hazzik merged commit a6a3c53 into nhibernate:master Jan 29, 2018
@hazzik
Copy link
Member

hazzik commented Feb 21, 2018

For proper attribution it would be better if this PR is squashed/merged by Alexander. If I squash/merge it myself only Gunnar and me would appear on the master commit.

Apparently GitHub supports co-authors for commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants