예제 #1
0
        /// <summary>Creates dapper action.</summary>
        /// <typeparam name="T2">Generic type parameter.</typeparam>
        /// <param name="mapperKey">The mapper key.</param>
        /// <param name="actionKind">The action kind.</param>
        /// <param name="selectors">A variable-length parameters list containing selectors.</param>
        /// <returns>The new dapper action.</returns>
        public DapperPlusActionSet <T2> CreateDapperAction <T2>(string mapperKey, DapperPlusActionKind actionKind, params Func <TEntity, T2>[] selectors)
        {
            // FROM: ThenBulkAction

            var action = new DapperPlusActionSet <T2>(this);

            if (selectors == null)
            {
                return(action);
            }

            if (Current != null)
            {
                var childs = selectors.Select(x => Current.Select(x).ToList()).ToList();
                action.AddAction(mapperKey, actionKind, childs);
            }
            else if (CurrentItem != null)
            {
                var childs = selectors.Select(x => x(CurrentItem)).ToList();
                action.AddAction(mapperKey, actionKind, childs);
            }

            return(action);
        }
예제 #2
0
        /// <summary>Creates dapper action.</summary>
        /// <typeparam name="T1">Generic type parameter.</typeparam>
        /// <typeparam name="T2">Generic type parameter.</typeparam>
        /// <param name="mapperKey">The mapper key.</param>
        /// <param name="actionKind">The action kind.</param>
        /// <param name="selectors">A variable-length parameters list containing selectors.</param>
        /// <returns>The new dapper action.</returns>
        public DapperPlusActionSet <T2> CreateDapperAction <T1, T2>(string mapperKey, DapperPlusActionKind actionKind, params Func <T1, T2>[] selectors)
        {
            // FROM: Extensions.AlsoBulKAction

            var action = new DapperPlusActionSet <T2>(this);

            if (selectors == null)
            {
                return(action);
            }

            if (Current != null)
            {
                var childs = selectors.Select(x => ((IEnumerable <T1>)Current).Select(x).ToList()).ToList();
                AddAction(mapperKey, actionKind, childs);
            }
            else if (CurrentItem != null)
            {
                var childs = selectors.Select(x => ((IEnumerable <T1>)CurrentItem).Select(x).ToList()).ToList();
                AddAction(mapperKey, actionKind, childs);
            }

            return(action);
        }
예제 #3
0
        /// <summary>An IDbConnection extension method that bulk action asynchronous.</summary>
        /// <param name="connection">The connection to act on.</param>
        /// <param name="asyncAction">The asynchronous action.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A Task.</returns>
        public static Task BulkActionAsync(this IDbConnection connection, Action <DapperPlusActionSet <object> > asyncAction, CancellationToken cancellationToken = default(CancellationToken))
        {
            var actionSet = new DapperPlusActionSet <object>(connection, cancellationToken);

            return(Task.Run(() => asyncAction(actionSet), cancellationToken));
        }