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

Linq: add enum Equals and object Equals support #3242

Merged
merged 20 commits into from
May 17, 2023

Conversation

tykovec
Copy link
Contributor

@tykovec tykovec commented Feb 22, 2023

No description provided.

@tykovec tykovec changed the title Add Enum Equals support Lina: add Enum Equals support Feb 23, 2023
@tykovec
Copy link
Contributor Author

tykovec commented Feb 23, 2023

Seems not so easy with enum equals as it is boxed into object.Equals(object) expression (what leads to problem in my first iteration with BaseHqlGeneratorForMethod approach)

@tykovec tykovec changed the title Lina: add Enum Equals support Linq: add Enum Equals support Feb 23, 2023
@bahusoid
Copy link
Member

We have EqualsGenerator class with registrations for various Equals methods. Can't it be simply extended with additional registration for Enum.Equals?

@tykovec
Copy link
Contributor Author

tykovec commented Mar 24, 2023

We have EqualsGenerator class with registrations for various Equals methods. Can't it be simply extended with additional registration for Enum.Equals?

I tried it but it is throwing exception:

System.InvalidOperationException : The binary operator Equal is not defined for the types 'NHibernate.DomainModel.Northwind.Entities.Gender' and 'System.Object'.

Stack Trace: 
Expression.GetEqualityComparisonOperator(ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull)
Expression.Equal(Expression left, Expression right, Boolean liftToNull, MethodInfo method)
Expression.Equal(Expression left, Expression right)
EqualsGenerator.BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) line 79
HqlGeneratorExpressionVisitor.VisitMethodCallExpression(MethodCallExpression expression) line 605

GetMethodBasedBinaryOperator is expecting that types on both sides of equal operation are same ...

@bahusoid
Copy link
Member

bahusoid commented Mar 24, 2023

Stacktrace shows the same source of exception:

EqualsGenerator.BuildHql

I can't look into it right now. But I'm pretty sure EqualsGenerator.BuildHql can be adjusted (like casting to object one of argument) to make it work

@tykovec
Copy link
Contributor Author

tykovec commented Mar 24, 2023

I tried it but Enum.Equals is [MethodImplAttribute(MethodImplOptions.InternalCall)] and when i try to get method ReflectHelper.GetMethodDefinition<Enum>(x => x.Equals(default(Enum))) this is evaluated to object.Equals and then is EqualsGenerator class used for object.Equals comparison which is not wanted.

@bahusoid
Copy link
Member

then is EqualsGenerator class used for object.Equals comparison which is not wanted.

Why? Does it cause any particular issues (except mentioned problem from EqualsGenerator.BuildHql)? Maybe we just need to register object.Equals.

@tykovec tykovec changed the title Linq: add Enum Equals support Linq: add enum Equals and object Equals support Mar 27, 2023
@hazzik
Copy link
Member

hazzik commented Mar 31, 2023

hi @tykovec could you please remove unrelated formatting changes?

@tykovec tykovec force-pushed the enumqualssupport branch from 3a9a98e to f929aed Compare April 1, 2023 13:09
@tykovec tykovec force-pushed the enumqualssupport branch from f929aed to e7913b9 Compare April 1, 2023 13:11
@tykovec
Copy link
Contributor Author

tykovec commented Apr 1, 2023

hi @tykovec could you please remove unrelated formatting changes?

done, btw were you not thinking about some code cleanup rules or something like that, white spaces and spacing is really mess ...

@tykovec
Copy link
Contributor Author

tykovec commented Apr 1, 2023

@hazzik how can i retrigger teamcity build, has some issue with cleanup ....

@fredericDelaporte
Copy link
Member

I have relaunched them.

@hazzik
Copy link
Member

hazzik commented Apr 2, 2023

@fredericDelaporte I actually had to restart the build agent, sorry, did not have time to re-queue tests

@tykovec
Copy link
Contributor Author

tykovec commented May 4, 2023

@bahusoid @hazzik -> i have repushed changes, now there is no problem with team city builds, needs successful merge something more?

Tomas Lukac and others added 2 commits May 12, 2023 09:43
@hazzik hazzik enabled auto-merge (squash) May 17, 2023 11:35
@hazzik hazzik merged commit c52c7f1 into nhibernate:master May 17, 2023
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.

4 participants