What is the purpose of Dapper's [ExplicitKey] attribute? In this example generated SQL is absolutely identical, regardless of whether the key is applied or not.
exec sp_executesql
N'insert into InvoiceDetail ([InvoiceID], [Detail]) values (@InvoiceID, @Detail);
select SCOPE_IDENTITY() id',N'@Detail nvarchar(4000),@InvoiceID int',@Detail=N'Insert_Single_1',@InvoiceID=4
This is why the attribute exists:
https://github.com/StackExchange/Dapper/issues/351
The [Key] attribute assumes an autoincremented key, and when you try to pass a custom (e.g. non-int) key instead, Insert and InsertAsync fail with NullReferenceException, even if the passed value clearly isn't null. So [ExplicitKey] was introduced to handle those instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With