henkmollema / Dommel

CRUD operations with Dapper made simple.
MIT License
611 stars 99 forks source link

Support Primary Key of type GUID retrieval on Insert #80

Closed Gremlin80 closed 5 years ago

Gremlin80 commented 6 years ago

Actually if there is a Primary Key Id of type int,, the insert returns the newly server-generated int value when adding records. Would be great to also support another type of Primary Key , Guid also server generated. the fix can be done (in t-sql) with the same scope_identity function, avoiding to cast to int always but taking in account the Guid type

henkmollema commented 6 years ago

What would such query look like?

henkmollema commented 5 years ago

@Gremlin80 this was added in dc475daf8272fb92649ae42f52c4f31cb1ab5f03 and is available in the latest 2.0 beta release on MyGet and will be available in the next 2.0.0-beta4 release.

You can override the default insert query behavior and use the output inserted.<Id Column> syntax to return the generated Guid from the query:

https://github.com/henkmollema/Dommel/blob/dc475daf8272fb92649ae42f52c4f31cb1ab5f03/test/Dommel.IntegrationTests/InsertGuidTests.cs#L19-L23