How do I rollback a failed InsertOnSubmit? (VB.NET LINQ) -


i'm having problem undoing failed insertonsubmit when submitchanges fails. here's code:

    dim newfac new t_facility             {.fk_instance_id = guinstance_id,              .fk_accounttype_id = guaccounttype_id,              .fk_atp_id = guatp_id,              .fk_repayment_id = gurepaymenttype_id,              .fk_interesttype_id = guinteresttype_id,              .fk_ft_id = gufacilitiestype_id,              .newrecord = bnewrecord,              .indexnum = iindexnum,              .sortcode = ssortcode,              .accountnumber = saccountnumber,              .balance = decbalance,              .lastsanction = declastsanctioned,              .proposed = decproposed,              .term_mths = iterm_mths,              .term_expiry = dterm_expiry,              .interestrate = decinterestrate,              .arrangementfee = decarrangementfee,              .datetime_from = now(),              .id = gufacilities_id}     db.t_facilities.insertonsubmit(newfac)     try         db.submitchanges()     catch e exception         console.writeline(e)         messagebox.show(e.message & ". please correct field , try again", "error", messageboxbutton.ok, messageboximage.stop)          exit sub 'takes user form correct value     end try 

when hit submit again, comes around , fails @ same point with same values original submission ignoring new values user input.

the values in "newfac" corrected new values. i've checked them on line manually in debug: "db.t_facilities.insertonsubmit(newfac)"

i assume need somehow remove failed "newfac" contains incorrect values "db.t_facilities.insertonsubmit(newfac)" in catch somehow, don't see way this?

fyi: got principal of approach here: https://msdn.microsoft.com/en-us/library/bb763516

any appreciated.

now this not going technically correct, informed; please feel give real reason worked (so not based on statement of fact other worked, , entirely opinion - worked):

the solution dawned on me while reading through several questions various other people having similar issues (all using various ways of programmatically looping through datacontext looking match), changes added datacontext appears act offline clr of database, if insertonsubmit added it, stands reason deleteonsubmit should remove right?

so in mind, tried this:

db.t_facilities.insertonsubmit(newfac) try     db.submitchanges() catch e exception     console.writeline(e)     messagebox.show(e.message & ". please correct field , try again", "error", messageboxbutton.ok, messageboximage.stop)      db.t_facilities.deleteonsubmit(newfac)      exit sub 'takes user form correct value end try 

it worked! :d

so may totally wrong why worked (please inform me why - i'd genuinely know), worked.

edit: if can give correct reason worked, i'll accept answer instead of own


Comments