This is a migrated thread and some comments may be shown as answers.

How to save in database without committing

5 Answers 100 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
test
Top achievements
Rank 1
test asked on 10 Oct 2010, 08:51 PM
Hi,

I've a table with an identity column, when I insert a row in this table, I need to get the value of the identity column to continue my process, but I don't want to commit the identity column's value before the end of my process.

When I use the SaveChanges() function commit is done. I see in "old posts" we can use the Flush() function to do updates on database without commiting but I think it seems to be with old versions of OpenAccess.

So my question is : How can I do to solve my problem with the last version of OpenAccess ?

Thanks for your help and advices.

5 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 11 Oct 2010, 12:25 AM
Hi test,

You're right the Flush method is the way to go and you're also right that it is not part of the new Context API yet, but only available in the Classic approach.
However, what you can do is to extend the generated Context class deriving from OpenAccessContext and then expose the scope in a public property like (pseudo code):

public partial class MyScopeContext : MyContext
{

   public IObjectScope GetObjectScope()
   {
       return this.GetScope();
   }
}

Each OpenAccessContext subclass has an underlying scope which you can access with the protected GetScope() method.
Don't forget to create the new partial class in a new code file (.cs) so it doesn't get overwritten when you generate.

So, to call Flush on a context you do:

MyScopeContext.GetObjectScope().Flush();

Regards

Henrik
0
test
Top achievements
Rank 1
answered on 11 Oct 2010, 10:23 AM
Thanks  Henrik,

The problem is : I don't find any method "flush" in IObjectScope interface, in fact I find it nowhere. Any idea ?
0
IT-Als
Top achievements
Rank 1
answered on 11 Oct 2010, 10:28 AM
Hi Test,

Sorry... a typo.

You will need to go to ObjectScope.Transaction.Flush();

Be aware that Context.RevertChanges() will rollback the flushed changes if done after a ObjectScope.Transaction.Flush();

Regards

Henrik
0
test
Top achievements
Rank 1
answered on 11 Oct 2010, 10:41 AM
;-)

I came back here to write the same things. I found Flush in Transaction.

Thanks for your response and your speed.
0
Accepted
IT-Als
Top achievements
Rank 1
answered on 11 Oct 2010, 10:43 AM
Hi test,

Glad you (and I :-)) found the answer.

Maybe you can mark the question (and post preferably also) as answered so that other users of the forum can find their answer quickly for a related question. Thanks.

Regards

Henrik
Tags
Development (API, general questions)
Asked by
test
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
test
Top achievements
Rank 1
Share this question
or