DapperLib / DapperLib/Dapper

Equals / GetHashCode inconsistent in Identity object

Open
#1,122 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

Hi,
is there a reason why when pre-computing hashCode in Identity, otherTypes parameter is included but when comparing to other in Equals, it is not included?

https://github.com/StackExchange/Dapper/blob/master/Dapper/SqlMapper.Identity.cs

AFAIK, when two object equal, they should have the same hashcode, but if two identity objects were created with different otherTypes parameter, they won't.

We are occasionally seeing a production exception coming from multimap caused by an incorrect type cast. We think it might be caused by the same sql query used in MultiMap with different generic parameters where a deserializer cached for type X is returned for a different type Y. But we can't reproduce it reliably though.

Update: we linked our project to dapper source code for another round of debugging and now we are pretty sure our issue is caused by the Equals/GetHashCode inconsistency.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Dapper/SqlMapper.Identity.cs and trace Identity.Equals alongside the precomputed GetHashCode, focusing on the otherTypes parameter. Then inspect the identity cache and MultiMap path for a regression case involving different generic parameters; done means equal identities produce matching hashes and the incorrect deserializer cast is no longer observed.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.