How to use transaction

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
afva
Posts: 39
Joined: Thu 13 Aug 2009 21:22

How to use transaction

Post by afva » Tue 29 Mar 2011 09:49

Hello,

I do not know how to use Oracle.Transactions in my code.
My code looks like this:

I have a public class BaseAdapter from wich all my adapters inherit and where I put my save() etc like this:

Code: Select all

public class BaseAdapter where T : Devart.Data.Linq.DataContext, new()
    {
        protected T DB; 
        StringBuilder sb = new StringBuilder();

        public BaseAdapter()
        {
            DB = new T();
            // Voorlopig willen we de output zien
            DB.Log = new System.IO.StringWriter(sb);
            DB.Log = Console.Out;            
        }

        public void Dispose()
        {
            this.DB.Dispose();
        }

        public bool Save()
        {
            try
            {
                ChangeSet cs = DB.GetChangeSet();
DB.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                return true;
            }
            catch (Devart.Data.Linq.ChangeConflictException e)
            { ...
            }
            catch (OracleException ex)
            {...
            }
            catch (Exception ex)
            {...
            }
        }

My adapters inherit from this baseAdapter like this:

Code: Select all

   public class InskSetAdapter : BaseAdapter
    {
       public void addVES(CT_VES ves_ipar)
        {
            DB.CT_VES.InsertOnSubmit(ves_ipar);
        }
    }
In my program I use the code like this:

Code: Select all

InskSetAdapter inskAdapter = new InskSetAdapter();
CT_VES ves_rec = new CT_VES();
// do something with ves_rec 
inskAdapter.addVES(ves_rec);
inskAdaper.Save();
Where and how can I put the use of transactions??

I want to use it something like:

Code: Select all

InskSetAdapter inskAdapter = new InskSetAdapter();
CT_VES ves_rec = new CT_VES();
// do something with ves_rec 

// BeginTransaction
// Again do something with ves_rec 
// if (ok) then Transaction.Commit();
// else Transaction.Rollback();

inskAdapter.addVES(ves_rec);
inskAdaper.Save();

Thanks,

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 30 Mar 2011 14:17

Could you please specify the operations you want to wrap in a transaction? As far as I can understand, no interoperations with the server are performed before the inskAdaper.Save() call. In this case, opening a transaction will not affect the way you are working with ves_rec.

Generally, DataContext starts and commits (or rolls back) a transaction implicitly inside the SubmitChanges() method. Thus, there is no need to begin a transaction explicitly, unless you need, e.g., to wrap several SubmitChanges calls in a single transaction. For more information about this, please refer to the corresponding topic in the LinqConnect documentation:
http://www.devart.com/linqconnect/docs/ ... tions.html

Post Reply