示例#1
0
        public (bool, int) Commit()
        {
            bool res = false;
            int  num = 0;

            try
            {
                using (var con = _conFactory.CreateCon())
                {
                    con.Open();
                    IDbTransaction trans = con.BeginTransaction();
                    try
                    {
                        if (this.Workers.Count > 0)
                        {
                            while (Workers.Count > 0)
                            {
                                EntityWorker worker = Workers.Dequeue();
                                con.Execute(worker.SqlBuilder.Invoke(worker.Data), worker.Data, trans);
                                num++;
                            }
                            trans.Commit();
                            this.Workers.Clear();
                        }
                        res = true;
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        num = 0;
                    }
                    finally
                    {
                        if (con.State != ConnectionState.Closed)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(res, num);
        }
示例#2
0
        public bool Commit()
        {
            bool res = false;

            try
            {
                using (var con = _conFactory.CreateCon())
                {
                    con.Open();
                    IDbTransaction trans = con.BeginTransaction();
                    try
                    {
                        foreach (var item in this.Works)
                        {
                            con.Execute(item.SqlBuilder.Invoke(item.Data), item.Data, trans);
                        }
                        trans.Commit();
                        this.Works.Clear();
                        res = true;
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                    }
                    finally
                    {
                        if (con.State != ConnectionState.Closed)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(res);
        }