Skip to content

Commit da4b6c9

Browse files
maca88fredericDelaporte
authored andcommitted
Fix QueryKey Equals method
1 parent 8e98169 commit da4b6c9

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/NHibernate/Cache/QueryKey.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace NHibernate.Cache
1414
{
1515
[Serializable]
16-
public class QueryKey : IDeserializationCallback
16+
public class QueryKey : IDeserializationCallback, IEquatable<QueryKey>
1717
{
1818
private readonly ISessionFactoryImplementor _factory;
1919
private readonly SqlString _sqlQueryString;
@@ -93,47 +93,51 @@ public QueryKey SetMaxRows(int[] maxRows)
9393

9494
public override bool Equals(object other)
9595
{
96-
QueryKey that = (QueryKey)other;
97-
if (!_sqlQueryString.Equals(that._sqlQueryString))
96+
return Equals(other as QueryKey);
97+
}
98+
99+
public bool Equals(QueryKey other)
100+
{
101+
if (other == null || !_sqlQueryString.Equals(other._sqlQueryString))
98102
{
99103
return false;
100104
}
101-
if (_firstRow != that._firstRow
102-
|| _maxRows != that._maxRows)
105+
106+
if (_firstRow != other._firstRow || _maxRows != other._maxRows)
103107
{
104108
return false;
105109
}
106110

107-
if (!Equals(_customTransformer, that._customTransformer))
111+
if (!Equals(_customTransformer, other._customTransformer))
108112
{
109113
return false;
110114
}
111115

112116
if (_types == null)
113117
{
114-
if (that._types != null)
118+
if (other._types != null)
115119
{
116120
return false;
117121
}
118122
}
119123
else
120124
{
121-
if (that._types == null)
125+
if (other._types == null)
122126
{
123127
return false;
124128
}
125-
if (_types.Length != that._types.Length)
129+
if (_types.Length != other._types.Length)
126130
{
127131
return false;
128132
}
129133

130134
for (int i = 0; i < _types.Length; i++)
131135
{
132-
if (!_types[i].Equals(that._types[i]))
136+
if (!_types[i].Equals(other._types[i]))
133137
{
134138
return false;
135139
}
136-
if (!Equals(_values[i], that._values[i]))
140+
if (!Equals(_values[i], other._values[i]))
137141
{
138142
return false;
139143
}
@@ -144,16 +148,16 @@ public override bool Equals(object other)
144148
// issues on deserialization if GetHashCode or Equals are called in its deserialization callback. And
145149
// building sets or dictionaries on the fly will in most cases be worst than BagEquals, unless re-coding
146150
// its short-circuits.
147-
if (!CollectionHelper.BagEquals(_filters, that._filters))
151+
if (!CollectionHelper.BagEquals(_filters, other._filters))
148152
return false;
149-
if (!CollectionHelper.BagEquals(_namedParameters, that._namedParameters, NamedParameterComparer.Instance))
153+
if (!CollectionHelper.BagEquals(_namedParameters, other._namedParameters, NamedParameterComparer.Instance))
150154
return false;
151155

152-
if (!CollectionHelper.SequenceEquals<int>(_multiQueriesFirstRows, that._multiQueriesFirstRows))
156+
if (!CollectionHelper.SequenceEquals(_multiQueriesFirstRows, other._multiQueriesFirstRows))
153157
{
154158
return false;
155159
}
156-
if (!CollectionHelper.SequenceEquals<int>(_multiQueriesMaxRows, that._multiQueriesMaxRows))
160+
if (!CollectionHelper.SequenceEquals(_multiQueriesMaxRows, other._multiQueriesMaxRows))
157161
{
158162
return false;
159163
}

0 commit comments

Comments
 (0)