I have a stored procedure that writes data to a table, based on values from a different table. So, it reads the start/end dates from a table, then creates a whole lot of data and writes it to a separate table.
What happens is the user selects a Start/End date for something, and then I store the start/end date into a table. I then call the stored procedure, from within EF, and that procedures reads from the table just updated, and populates a different table.
If the proc fails, I want to roll back any data that the proc wrote, as well as the initial update of the table.
I think the data is only written to the table (The initial update, done in EF) when you call the 'SaveChanges'. So I call that, and THEN call the procedure. Is there a way to detect if the procedure failed, and if so, rollback ALL udpates (The table update, and anything the proc did)?
Currently, my code looks like this, but it seems a paremeter in SaveChanges is invalid (wants no parameters), and 'AcceptAllChanges' is invalid:
using (var scope = new TransactionScope()) { Context.SaveChanges(false); Context.project_scheduled_event_payments(st.id); Context.AcceptAllChanges(); }