Skip to content

Enhancement: New Compiler Possible Collision Problem - Refactor the DbDataReader GetHashCode() Generator #597

@mikependon

Description

@mikependon

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;
}

Metadata

Metadata

Assignees

Labels

deployedFeature or bug is deployed at the current releaseenhancementNew feature or requestfixedThe bug, issue, incident has been fixed.priorityTop priority feature or things to dorefactoringA change in code without changing the logictodoThings to be done in the future

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions