Dapper.Contrib icon indicating copy to clipboard operation
Dapper.Contrib copied to clipboard

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

Open stephane3434 opened this issue 8 years ago • 0 comments

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)

1) 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

2) 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

stephane3434 avatar Jan 05 '18 20:01 stephane3434