This is a migrated thread and some comments may be shown as answers.
Transaction handling
7 Answers 81 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dave
Top achievements
Rank 1
Dave asked on 05 Aug 2011, 01:18 AM
Hi Telerik Team,

How can I achieve the following scenario in OpenAccess where I can easily achieve in Linq to Sql.
I want to finish all changes in one transaction.
What I need is I want to read back the changes I made to DB before actual commit.

// Update some data.

// Read Updated data

// Delete or Insert to other tables

// SaveChanges();

In Linq to Sql, I can achieve by

context.BeginTransaction()

try
{
// Update some data.
context.SubmitChanges();  (Already changed in DB)


// Read Updated data 

// Delete or Insert to other tables
context.SubmitChanges(); (Already changed in DB)


context.Transaction.Commit();
}
catch
{
context.Transaction.Rollback();
}
And it make sure ACID.

Thanks

7 Answers, 1 is accepted

Sort by
0
Accepted
IT-Als
Top achievements
Rank 1
answered on 05 Aug 2011, 08:06 AM
Hi Kyaw,

I am not sure this is the official way of doing so, but what you'll need is what is known as Flush method in the Classic API.

To get a hand on the underlying ObjectScope (that is the Context equivalent in the Classic API), you can provide a property getter on your Context class  like:

public MyContext : OpenAccessContext
{

   public IObjectScope ObjectScope
   {
       get { return this.GetScope(); }
   }
}

and then in your method where you need to read the updated info you do:

// "Soft Commit" the changes
Context.ObjectScope.Flush();

// Read the object again with the changes

// Do a final commit
Context.SaveChanges();

This is a little cumbersome, but as far as I remember the Flush functionality (or a equivalent) is not available in the Context API yet..

Let me know if it works out for you...

Regards

Henrik
0
Dave
Top achievements
Rank 1
answered on 05 Aug 2011, 10:23 AM
Hi Henrik,

Thanks a million. You save my day.

Finally I come out with this extended code.
Why they hide such kind of useful functions inside?

As I can write the extended code in another partial class, no need to worry of overwritten by auto generated codes where every time we make changes to Model.

 

 

 

 

public partial class EntityModel
    {
        public IObjectScope ObjectScope
        {
            get { return this.GetScope(); }
        }
  
        public void Flush()
        {
            GetScope().Transaction.Flush();
        }
    }

Thanks and Regards,
Kyaw Myint Aung

0
IT-Als
Top achievements
Rank 1
answered on 05 Aug 2011, 10:27 AM
Hi Kyaw,

Great it did work out for you.

Maybe someone from Telerik can elaborate on if the Flush (or equivalent method or functionality) will be made available in the Context API or is already there..

Regards
Henrik
0
Dave
Top achievements
Rank 1
answered on 05 Aug 2011, 10:37 AM
Hi Henrik,

As I am using Q2 2011, the method is not exposed yet in Context API.

Regards,
Kyaw Myint Aung

0
Ivailo
Telerik team
answered on 05 Aug 2011, 02:44 PM
Hi,

First let me thank Henrik for helping out on this issue. We can confirm that his advice is valid as per the Q2 2011 release of Telerik OpenAccess ORM.

As for including the flush functionality in the context API, we will most certainly do it in one of the future releases.

Let us know if we can be of any assistance.

All the best,
Ivailo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
IT-Als
Top achievements
Rank 1
answered on 05 Aug 2011, 02:46 PM
Hi Ivailo,

Thanks for joining and elaborating on the issue. Looking forward to see this in the Context API
0
Dave
Top achievements
Rank 1
answered on 06 Aug 2011, 09:15 AM
Hi Ivailo,

Thanks for joining.

Could you also see and acknowledge of my other two threads regarding to Stored Procedure and Transaction?
link1 and link2

It is important for us in development.

Any help would be appriciated.

Thanks.
Tags
Development (API, general questions)
Asked by
Dave
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Dave
Top achievements
Rank 1
Ivailo
Telerik team
Share this question
or