DapperLib / DapperLib/Dapper.Contrib
Dapper.Contrib Insert<T>(Enumerable<T> list) -> list<T> with key valued
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
I was looking through the code SqlMapperExtensions.cs in dapper.contrib
At line 386 I can find this:
var cmd = $"insert into {name} ({sbColumnList}) values ({sbParameterList})";
returnVal = connection.Execute(cmd, entityToInsert, transaction, commandTimeout);
I was looking for a way to get as output the same list in input but with Id (the field with [Key] parameter) valued.
I was thinking about something like this:
var cmd = $"insert into {name} ({sbColumnList}) OUTPUT {sbInsertedColumnList} , Insert.WhenCreated into @Inserted values ({sbParameterList}); SELECT * FROM @Inserted";
returnVal = connection.Query<T>(cmd, entityToInsert, transaction, commandTimeout);
where {sbInsertedColumnList} is the same as {sbColumnList} but with Inserted. as prefix for any column.
Could this be a good idea?
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 SqlMapperExtensions.cs around line 386 and trace the Dapper.Contrib Insert(IEnumerable) path, including how the [Key] field is handled. Clarify the expected returned list and database-specific behavior with maintainers; done means an agreed implementation that returns inserted entities with their key values.
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