Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I ensure an idempotent database insert with Entity Framework 5?

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

http://blogs.msdn.com/b/adonet/archive/2013/03/11/sql-database-connectivity-and-the-idempotency-issue.aspx

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?

like image 424
Steve S Avatar asked Mar 16 '13 09:03

Steve S


1 Answers

Release 6.1 of Entity Framework will solve this issue. (Thanks EF team - fabulous work.)

https://entityframework.codeplex.com/wikipage?title=Handling%20of%20Transaction%20Commit%20Failures%20

like image 69
Steve S Avatar answered Oct 11 '22 13:10

Steve S