How to "unwind" one or more InsertOnSubmit() calls

How to "unwind" one or more InsertOnSubmit() calls

Postby -marcelo- » Tue 29 Aug 2017 16:29

Before stating my question: I´ll be using only one DataContext througout the entire application.

My question is as follow:
Suppose I called InsertOnSubmit() repeatedly for one or more entities, but before SubmitChanges() call, some external event (user changed her mind, some new data arrived) all the inserts must be discarded. And not to be included in some other SubmitChanges() from another part of the app.

Of course, if I were using one DataContext for this transaction only, it´s not a problem; simply Dispose it.

But because all editions must be done on instances read by the same DataContext (*), it seems to me more convenient to create the context at the app startup and use it for everything.

(*) I tried to Attach() a disconnected instance before call SubmitChanges(), but received an exception.

Any help will be appreciated.
-marcelo-
 
Posts: 16
Joined: Wed 28 Jun 2017 12:35

Re: How to "unwind" one or more InsertOnSubmit() calls

Postby Shalex » Wed 30 Aug 2017 10:29

Please refer to https://www.devart.com/linqconnect/docs/?DeletingEntities.html.

If this doesn't help, tell us how we should modify this sample to reproduce the issue:
Code: Select all
    // var monitor = new Devart.Data.Linq.Monitoring.LinqMonitor() { IsActive = true };

    using (var context = new MyDataContext()) {

        var dept = new DEPT() { DEPTNO = 11, DNAME = "test", LOC = "test" };
        context.DEPTs.InsertOnSubmit(dept);

        dept.DNAME = "newName";
        context.DEPTs.DeleteOnSubmit(dept);

        context.SubmitChanges();
    }

Also specify the exact text of the error and its full stack trace.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for PostgreSQL