nhibernate-core icon indicating copy to clipboard operation
nhibernate-core copied to clipboard

NH-3845 - Make OfType work better with polymorphic mappings

Open abrobston opened this issue 9 years ago • 14 comments

Addresses NH-3845. The ProcessOfType Linq visitor class now handles interfaces and base classes by checking which mapped types that could be in the result set implement the class, then filtering accordingly. If no results are possible, any remaining filters are removed from the query tree to avoid problems with invalid property names.

Because the HQL tree for OfType can now mimic the ".class IN" construct, the In method of HqlTreeBuilder was inadequate to express the tree. Allowing an array of nodes to be passed as the source solves this problem.

abrobston avatar Feb 14 '16 20:02 abrobston

I believe that you need to use ExpressionList instead of modifying In

hazzik avatar Feb 14 '16 20:02 hazzik

I tried using ExpressionList, and it causes an exception at parse time. When using the HQL construct where EntityName.class in (Some.Class, Some.Other.Class), the parse tree places the two class names (as Ident nodes) as direct children of the InList node, which in turn is the child of the In node. The changes in this commit replicate that behavior.

abrobston avatar Feb 14 '16 22:02 abrobston

Ok, understand. Please remove usage of C#6 language features

hazzik avatar Feb 15 '16 05:02 hazzik

I found another facet of the same bug, and I'm likely to be amending the pull request once I can create a minimal test case for it.

abrobston avatar Feb 15 '16 16:02 abrobston

You will also need to check the caching issues. Please check that query do process correctly with regardless the type you specify.

hazzik avatar Feb 19 '16 00:02 hazzik

@hazzik, I'm not entirely sure what you mean when referring to "check the caching issues." Do you have a test case or example of some kind? Or, can you tell me where to look for a similar unit test?

abrobston avatar Feb 19 '16 00:02 abrobston

Start exploring from NH-2500 in JIRA. I can provide more resources later

hazzik avatar Feb 19 '16 02:02 hazzik

I added two unit test methods to check for cache issues similar to those NH-2500 describes. The tests pass. If there are other scenarios I should check, please let me know.

abrobston avatar Feb 19 '16 16:02 abrobston

I'm having some issues with another test case that I found does not pass. I posted to the nhibernate-developers Google Group, so see discussion there once my post is released from moderation.

abrobston avatar Feb 22 '16 22:02 abrobston

The Google Group thread has one reply, but more information would be very helpful.

abrobston avatar Feb 25 '16 17:02 abrobston

Related to #553. The #553 contains more clear logic, which, I think shall be ported here.

hazzik avatar Feb 14 '17 21:02 hazzik

Happy birthday, PR!

hazzik avatar Feb 14 '17 21:02 hazzik

I've extracted the issue with unmapped base classes and interfaces to a new feature request NH-3947.

hazzik avatar Feb 14 '17 23:02 hazzik

Can you please enable Allow edits from maintainers option on this PR?

hazzik avatar Jun 24 '17 03:06 hazzik