0

is there a way to roll back after a db.submitchanges without de need of transactions?

It would be a shame having to run a service special for loggings. Is there an alternative to roll back and not to use that special service?

thanks in advance!

EDIT:

What I really want: I have 2 database interactions I want to do right after each other.

let's say, I want to add something in database table 'Slots'. After submitting this, I can receive the Id, which has been created by the auto-increment.

That Id, I want to use to insert a new log in the database. but when inserting into the logs fail, I want to rollback the action in 'Slots' too..

this is possible with transactions I believe, but it seems I'm not able to do this without getting errors. even when all servers are set to allow them and firewalls are off..

user1122844
  • 87
  • 4
  • 13
  • What special service are you talking about? What about the logging? I'm unclear what the question is. – usr May 07 '13 at 13:34

2 Answers2

0

No.

db.SubmitChanges() is opening a transaction itsself so avoiding it is not an option.

Not sure what you mean with loggin service, I guess you mean that you use the database for logging and you are using the same datacontext for writing the log to your database and your business-data so it can happen that your business data fails (so Rollback of the transaction) and also your logging is rolled-back.

The easiest solution is to use a speparate datacontext for your logging.

Update There is no need for multiple SubmitChanges in your case because you do not need the ID, you can add the entity to the log. Have a look here How do I get Id of a record without submitting and re-querying?

And since you can have only on SubmitChanges, it will all be in one transaction and it will do exactly what you want

Community
  • 1
  • 1
Pleun
  • 8,856
  • 2
  • 30
  • 50
-1

You should insert both the Slots and the log at the same time.

i have no idea of how your data model is build up but simplified.

Log myLog = new Log();
Slot mySlot = new Slot();
...
...

DataContext db = new DataContext();

db.Slots.InsertOnSubmit(mySlot);

myLog.Slot = mySlot;
myLog.... = ....;

db.Logs.InsertOnSubmit(myLog);

db.SubmitChanges();