Example #1
0
        /// <summary>
        /// 批量新增-独立事务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// Jerry 2009年3月23日 老刘修改了此方法 只Creat一次Command 减少内存的损耗 修改后方法见下方395行开始
        //public static bool Insert<T>(List<T> list)
        //    where T : EntityBase
        //{
        //    DataAccessBroker broker = DataAccessFactory.Instance();
        //    bool result = true;
        //    try
        //    {
        //        broker.BeginTransaction();
        //        Insert(list, broker);
        //        broker.Commit();
        //    }
        //    catch
        //    {
        //        result = false;
        //        broker.RollBack();
        //    }
        //    finally
        //    {
        //        broker.Close();
        //    }
        //    return result;
        //}

        public static bool Insert <T>(List <T> list)
            where T : EntityBase
        {
            DataAccessBroker broker = DataAccessFactory.Instance();
            bool             result = true;

            try
            {
                if (list != null && list.Count > 0)
                {
                    broker.BeginTransaction();
                    T t = list[0];
                    //string sqlString = "INSERT INTO " + t.OringTableSchema.TableName + " ( " + ParseInsertSQL(t.OringTableSchema.AllColumnInfo, "") + " ) VALUES( " + ParseInsertSQL(t.OringTableSchema.AllColumnInfo, broker.ParameterPrefix) + ")";
                    //broker.CreateCommandE(sqlString);

                    foreach (T entity in list)
                    {
                        Insert(entity, broker);
                    }
                    broker.Commit();
                }
            }
            catch (Exception ex)
            {
                result = false;
                broker.RollBack();
                throw ex;
            }
            finally
            {
                broker.Close();
                broker.Dispose();
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// 批量新增-独立事务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        public static bool Insert <T>(List <T> list)
            where T : EntityBase
        {
            DataAccessBroker broker = DataAccessFactory.Instance();
            bool             result = true;

            try
            {
                broker.BeginTransaction();
                Insert(list, broker);
                broker.Commit();
            }
            catch (Exception ex)
            {
                result = false;
                broker.RollBack();

                throw ex;
            }
            finally
            {
                broker.Close();
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// 批量保存-独立事务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        public static bool Save <T>(List <T> list)
            where T : EntityBase
        {
            DataAccessBroker broker = DataAccessFactory.Instance(InstanceName);
            bool             result = true;

            try
            {
                broker.BeginTransaction();
                Save <T>(list, broker);
                broker.Commit();
            }
            catch
            {
                result = false;
                broker.RollBack();
            }
            finally
            {
                broker.Close();
            }
            return(result);
        }
Example #4
0
        public static bool UpdateAndSave <T>(IEnumerable <T> list)
            where T : EntityBase, new()
        {
            DataAccessBroker broker = DataAccessFactory.Instance();
            bool             result = true;

            try
            {
                broker.BeginTransaction();
                UpdateAndSave <T>(list, broker);
                broker.Commit();
            }
            catch (Exception ex)
            {
                result = false;
                broker.RollBack();
                throw ex;
            }
            finally
            {
                broker.Close();
            }
            return(result);
        }