sapiens / SqlFu

Fast and versatile .net core data mapper/micro-orm
Other
229 stars 50 forks source link

MSSQL SCOPE_IDENTITY does not work with Guid/UniqueIdentifier primary keys #73

Closed SimplyAdam closed 8 years ago

SimplyAdam commented 9 years ago

SCOPE_IDENTITY is only useful for numeric identity columns. Since choosing Guid primary keys using newid() or newsequentialid() is getting more common, it would be good if InsertedId method would come back with the generated uniqueidentifier rather than DBNull.

Only way I know of is using the "OUTPUT Inserted.Id" where Id is the name of the primary key in the INSERT statement.

SimplyAdam commented 9 years ago

Just trying to be helpful..

SqlServerProvider class. Line 185. Perhaps instead of appending the SCOPE_IDENTITY to the command text, perhaps replacing the value( with something like string.format("OUTPUT Inserted.{0} value(", idKey). Dirty-ish workaround, but would work across all primary key types.

sapiens commented 9 years ago

The "OUTPUT Inserted.Id" is already used in SqlFu 3 (not released). I'll see how easy it is to integrate into v2, when I'll have some spare time. In the mean time, I accept a PR :)

SimplyAdam commented 9 years ago

Awesome to hear! Looking forward to using SQLFu in the new projects :-)

Accept PR? Sorry, not familiar with that?

sapiens commented 9 years ago

PR means Pull Request