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

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
-marcelo-
Posts: 26
Joined: Wed 28 Jun 2017 12:35

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

Post by -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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Wed 30 Aug 2017 10:29

Please refer to https://www.devart.com/linqconnect/docs ... ities.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.

Post Reply