Exemple #1
0
        private static Int32 DoAction <T>(this IEnumerable <T> list, Boolean?useTransition, Func <T, Int32> func, IEntitySession session) where T : IEntity
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            if (!list.Any())
            {
                return(0);
            }

            // 避免列表内实体对象为空
            var entity = list.First(e => e != null);

            if (entity == null)
            {
                return(0);
            }

            //var fact = entity.GetType().AsFactory();

            //!!! SQLite 默认使用事务将会导致实体队列批量更新时大范围锁数据行,回归到由外部控制增加事务
            //// SQLite 批操作默认使用事务,其它数据库默认不使用事务
            //if (useTransition == null)
            //{
            //    //session ??= fact.Session;
            //    useTransition = session.Dal.DbType == DatabaseType.SQLite;
            //}

            var count = 0;

            if (useTransition != null && useTransition.Value)
            {
                using var trans = session.CreateTrans();
                count           = DoAction(list, func, count);

                trans.Commit();
            }
            else
            {
                count = DoAction(list, func, count);
            }

            return(count);
        }