QueryAsync cannot insert multiple items and return a single record set.
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
I want to add multiple records to a table and get back the IDs, something like this:
var addedIDs = await connection.QueryAsync<int>(@"
insert into myTable (PropA, ProbB)
output inserted.MyID
values (@propA, @propB)",
items.Select( x => new { propA = x.A, propB = x.B });
That throws an exception from this line:
https://github.com/StackExchange/Dapper/blob/80231b4d2b2391bbb01c2cd7be75fbecfe0c0296/Dapper/SqlMapper.cs#L1686
This appears to be very deliberately applied to stop this from working (including a test in https://github.com/StackExchange/Dapper/commit/bb5a16ce7abc6468da741f33303d2212f2652d60)
It's not clear why this is blocked or what the correct behaviour should be, as I expect multiple records in my result set, so ExecuteAsync is no use - at best I get the last ID added only.
I think this may also be the cause of https://github.com/StackExchange/Dapper/issues/930
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 in Dapper/SqlMapper.cs at the linked line and review the test added in commit bb5a16ce7abc6468da741f33303d2212f2652d60. Compare the behavior of QueryAsync with ExecuteAsync and inspect the related issue #930. Done means the intended multi-row ID behavior is defined and covered by tests without breaking existing parameter handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100