I want to ensure that my database (SQL Server) updates are idempotent, similar in functionality to the blog post below, but using Entity Framework (v5, Database First ):
However, if I add an @Operation parameter to my insert proc, I get
"Error 2037: A mapping function bindings specifies a function ... but does not map the following function parameters: Operation"
(The @Operation would be a GUID, generated by the app, allowing the app to retry with the same GUID if it doesn't get a success response from the proc. The proc would write the GUID to a log table, and only perform the insert if the GUID doesn't exist - thus ensuring an idempotent transaction.)
Is there an elegant solution?
Release 6.1 of Entity Framework will solve this issue. (Thanks EF team - fabulous work.)
If I understood your query properly - How about applying a unique constraint on the column which holds the GUID and then if you don't get a success response back after EXECuting the proc, retry the insert.
Within the insert proc potentially use a try/catch or even query for the GUID value w/o Try/Catch and if it's there handle the exception or just exit the proc cleanly with a success message via the RETURN statement.
I don't think you'll need to do anything special on the EF side.
And one last thing, maybe wrap the CRUD insert/update statement inside a transaction to ensure that a value was in fact written like in the example provided.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.