DapperLib / DapperLib/Dapper.Contrib

Dapper.Contrib - Get and Insert methods fail occasionally(!) when [ExplicitKey] is used

Open
#81 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
293
Forks
109
PR merge metrics
No merged PRs in 30d

Description

We have a table with a SqlHierarchyId primary key, and on some occasions InsertAsync on it fails with "Cannot insert Null into Id field", as if the key isn't marked with [ExplicitKey] (it is):
https://stackoverflow.com/questions/49669149/dapper-contrib-insertasync-fails-to-insert-an-hierarchyid-key

It starts happening randomly and then stops happening randomly with the exact same data. Most of the time InsertAsync work just fine, and I have no idea how to reproduce the issue.

Get and GetAsync exhibit similar behaviour for complex keys. We have this problem with SqlHierarchyId, and the topicstarter with Guid key, but the exception is the same ("GetAll only supports an entity with a single [Key] or [ExplicitKey] property"), and again, it happens rarely and randomly, and is impossible to reproduce:
https://stackoverflow.com/questions/45880051/dapper-contrib-only-supports-an-entity-with-a-single-key-or-explicitkey?rq=1

The "solution" in both cases is to wait until the problem is gone (for me it's usually gone after 10-15 attempts) or simply use QueryAsync/ExecuteAsync instead, but that doesn't look like much of a solution. Is there any chance this can be looked at?

Thank you in advance!

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 the InsertAsync, Get, and GetAsync paths that inspect [ExplicitKey] and complex keys, using the two linked Stack Overflow reports as reproduction context. Investigate why the same data intermittently produces the null-key and single-key errors. Done means the behavior is explained and the affected operations handle SqlHierarchyId and Guid keys consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.