DapperLib / DapperLib/Dapper.Contrib
Dapper.Contrib - Get and Insert methods fail occasionally(!) when [ExplicitKey] is used
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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