DapperLib / DapperLib/Dapper.Contrib

dapper.contrib can insert <T> return the explicite key

Open
#67 0 comments 0 reactions 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

Hello,

I am looking to do a generic function

T entity = InsertGet <T> (obj);

the principle is to make an insert and automatically return the created entity.

The principle would be to recover the object actually created in the database with all calculated fields ...

With Dapper and Dapper.Contrib it's super simple in 2 lines:

var id = await idb.InsertAsync (entityToInsert, trx);
return idb.Get <T> (id);

it works perfectly if [Key] is a numerique Id

but it is possible to define an "explicitkey" in a class

image

When performing an insert

var code = con.Insert<farticles> (art);

code contains the first field of the table (ART_SEQ) and not the "ExplicitKey" (ART_CODE)

would it be possible to make an insert that returns the "ExplicitKey" (ART_CODE) and not id because this id field does not exist...

or

is it possible to create the généric function directly it would be very convenient because it will simplify a lot of code

generic function => T entity = InsertGet <T> (obj);

and and the same for update

generic function => T entity = UpdateGet <T> (obj);

Thanks for your help

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 by tracing the Insert and InsertAsync entry points, especially how [ExplicitKey] and the returned value are handled. Reproduce the farticles case with ART_SEQ and ART_CODE, then determine whether the requested InsertGet and UpdateGet behavior has a defined result and verify it against the database state.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.