-
Notifications
You must be signed in to change notification settings - Fork 934
Avoid unnecessary casting for Linq provider #2491
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
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
591f30e
Avoid unnecessary casting for Linq provider
maca88 05dd4d6
Fix tests
maca88 085a170
Avoid additional casting and add more test cases
maca88 492d1bd
Fix build
maca88 39cf3f5
Try fix firebird parameter regex
maca88 1aeaf37
Revert "Try fix firebird parameter regex"
maca88 c50939f
Skip failing tests for Firebird
maca88 010cf85
Fix odbc tests
maca88 c918327
Code review changes
maca88 a4d4df0
Code review changes
maca88 22c17ff
Update src/NHibernate/Linq/Visitors/HqlGeneratorExpressionVisitor.cs
maca88 0858dce
Remove unused variable
hazzik 6d76720
Extract GetParameterType and GetCandidateTypes methods
hazzik 3bdb598
Reduce complexity
hazzik b4888b7
Further reduce complexity
hazzik e31a9a5
Move UnwrapUnary to ParameterTypeLocator as it is too specific
hazzik d10a057
Remove list creation
hazzik 371b8df
It seems comment belongs here
hazzik 9d0bbb5
Avoid HashSet creation for candidate type calculation
bahusoid 3c10311
Move number type checks to TypeExtensions and extract additional meth…
hazzik 503aec2
Merge to single GetCandidateType
bahusoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/NHibernate.DomainModel/Northwind/Entities/NumericEntity.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace NHibernate.DomainModel.Northwind.Entities | ||
{ | ||
public class NumericEntity | ||
{ | ||
public virtual short Short { get; set; } | ||
|
||
public virtual short? NullableShort { get; set; } | ||
|
||
public virtual int Integer { get; set; } | ||
|
||
public virtual int? NullableInteger { get; set; } | ||
|
||
public virtual long Long { get; set; } | ||
|
||
public virtual long? NullableLong { get; set; } | ||
|
||
public virtual decimal Decimal { get; set; } | ||
|
||
public virtual decimal? NullableDecimal { get; set; } | ||
|
||
public virtual float Single { get; set; } | ||
|
||
public virtual float? NullableSingle { get; set; } | ||
|
||
public virtual double Double { get; set; } | ||
|
||
public virtual double? NullableDouble { get; set; } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/NHibernate.DomainModel/Northwind/Mappings/NumericEntity.hbm.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernate.DomainModel.Northwind.Entities" assembly="NHibernate.DomainModel"> | ||
<class name="NumericEntity"> | ||
<id name="Short"> | ||
<generator class="assigned" /> | ||
</id> | ||
|
||
<property name="NullableShort" /> | ||
<property name="Integer" not-null="true" column="`Integer`" /> | ||
<property name="NullableInteger" /> | ||
<property name="Long" not-null="true" column="`Long`" /> | ||
<property name="NullableLong" /> | ||
<property name="Decimal" not-null="true" column="`Decimal`" /> | ||
<property name="NullableDecimal" /> | ||
<property name="Single" not-null="true" column="`Single`" /> | ||
<property name="NullableSingle" /> | ||
<property name="Double" not-null="true" column="`Double`" /> | ||
<property name="NullableDouble" /> | ||
</class> | ||
</hibernate-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary cast is exists short/long with == / <= / >= operators could you add additional test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When comparing two different types
short == long
, a cast will always be added when the mapped sql type ofshort
andlong
are different. I am thinking of restoring the previous behavior ofEquals
in case a user wants to compare two different types without an explicit cast as this is not possible anymore in5.3
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the operators and methods should work exactly the same, otherwise the software developer might make an error about which one to use and under what condition. If not careful, sql clauses are created which can cause performance problems.
The strange thing is that it casts unnecessarily in short to short or long to long comparisons.
Equals method with == operator
CompareTo method result == 0 with == operator
CompareTo method result < 0 with <= operator
CompareTo method result > 0 with >= operator