Only in the new compiler. In order for us to ensure that the collision will not happen on the caching of the AOT Compiled Expression, we need to consider the caching of the following.
- HashCode of the Type
- HashCode of the Name of each DbDataReader Fields
- HashCode of the Type of each DbDataReader Fields
- HashCode of the Ordinal of each DbDataReader Fields <-- this is not yet there
Without the ordinal caching, the collision may happen ended-up multiple invalid casting exception (and/or data assignment).
connection.ExecuteQuery<Person>("SELECT Id, Name FROM Person;");
connection.ExecuteQuery<Person>("SELECT Name, Id FROM Person;");
The possible fix is very minimal, simply add the concatenation of the ordering.
private static long GetReaderFieldsHashCode(DbDataReader reader)
{
if (reader == null)
{
return 0;
}
var hashCode = (long)0;
for (var ordinal = 0; ordinal < reader.FieldCount; ordinal++)
{
// The spatial data type is null.
hashCode += string.Concat(reader.GetName(ordinal), "-", ordinal).GetHashCode() +
(reader.GetFieldType(ordinal)?.GetHashCode()).GetValueOrDefault();
}
return hashCode;
}
Only in the new compiler. In order for us to ensure that the collision will not happen on the caching of the AOT Compiled Expression, we need to consider the caching of the following.
Without the ordinal caching, the collision may happen ended-up multiple invalid casting exception (and/or data assignment).
The possible fix is very minimal, simply add the concatenation of the ordering.