Keys with custom GetHashCode are not added correctly to key-many-to-many/one-to-many dictionaries when FetchMode is not Select

Description

When initializing a dictionary for a ternary relationship and the reference to the key in the element is mapped with either the default or join fetch mode, then the keys are added to the dictionary before they are fully hydrated (Id only).

This causes a problem when the key entity has a custom Equals/GetHashCode because the hash code will be incorrect until it is fully hydrated. This would either cause an exception if GetHashCode was expecting a valid fully hydrated state, or all related element entities are added to the same key (since all the keys were added with the default state GetHashCode value).

Attached are tests that show that all children are added to the same key when the dictionary is hydrated.

When the mapping is explicitly set to use select fetch mode, then the keys are fully hydrated before being added to the dictionary.

Environment

None

Assignee

Unassigned

Reporter

Martin Francisco

Labels

None

Components

Affects versions

Priority

Major
Configure