/// <summary>
        ///
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="connection"></param>
        /// <param name="tableName"></param>
        /// <param name="where"></param>
        /// <param name="fields"></param>
        /// <param name="hints"></param>
        /// <param name="transaction"></param>
        /// <param name="statementBuilder"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task <UpdateExecutionContext> CreateAsync(Type entityType,
                                                                      IDbConnection connection,
                                                                      string tableName,
                                                                      QueryGroup where,
                                                                      IEnumerable <Field> fields,
                                                                      string hints = null,
                                                                      IDbTransaction transaction          = null,
                                                                      IStatementBuilder statementBuilder  = null,
                                                                      CancellationToken cancellationToken = default)
        {
            var key = GetKey(entityType, tableName, fields, hints, where);

            // Get from cache
            var context = UpdateExecutionContextCache.Get(key);

            if (context != null)
            {
                return(context);
            }

            // Create
            var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken);

            var request = new UpdateRequest(tableName,
                                            connection,
                                            transaction,
                                            where,
                                            fields,
                                            hints,
                                            statementBuilder);
            var commandText = await CommandTextCache.GetUpdateTextAsync(request, cancellationToken);

            // Call
            context = CreateInternal(entityType,
                                     connection,
                                     tableName,
                                     dbFields,
                                     fields,
                                     commandText);

            // Add to cache
            UpdateExecutionContextCache.Add(key, context);

            // Return
            return(context);
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="connection"></param>
        /// <param name="tableName"></param>
        /// <param name="where"></param>
        /// <param name="fields"></param>
        /// <param name="hints"></param>
        /// <param name="transaction"></param>
        /// <param name="statementBuilder"></param>
        /// <returns></returns>
        public static UpdateExecutionContext <TEntity> Create <TEntity>(IDbConnection connection,
                                                                        string tableName,
                                                                        QueryGroup where,
                                                                        IEnumerable <Field> fields,
                                                                        string hints = null,
                                                                        IDbTransaction transaction         = null,
                                                                        IStatementBuilder statementBuilder = null)
            where TEntity : class
        {
            var key = GetKey <TEntity>(tableName, fields, hints, where);

            // Get from cache
            var context = UpdateExecutionContextCache.Get <TEntity>(key);

            if (context != null)
            {
                return(context);
            }

            // Create
            var dbFields = DbFieldCache.Get(connection, tableName, transaction);
            var request  = new UpdateRequest(tableName,
                                             connection,
                                             transaction,
                                             where,
                                             fields,
                                             hints,
                                             statementBuilder);
            var commandText = CommandTextCache.GetUpdateText(request);

            // Call
            context = CreateInternal <TEntity>(connection,
                                               tableName,
                                               dbFields,
                                               fields,
                                               commandText);

            // Add to cache
            UpdateExecutionContextCache.Add <TEntity>(key, context);

            // Return
            return(context);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="connection"></param>
        /// <param name="tableName"></param>
        /// <param name="where"></param>
        /// <param name="fields"></param>
        /// <param name="hints"></param>
        /// <param name="transaction"></param>
        /// <param name="statementBuilder"></param>
        /// <returns></returns>
        public static async Task <UpdateExecutionContext <TEntity> > CreateAsync <TEntity>(IDbConnection connection,
                                                                                           string tableName,
                                                                                           QueryGroup where,
                                                                                           IEnumerable <Field> fields,
                                                                                           string hints = null,
                                                                                           IDbTransaction transaction         = null,
                                                                                           IStatementBuilder statementBuilder = null)
            where TEntity : class
        {
            var key = GetKey <TEntity>(tableName, fields, hints, where);

            // Get from cache
            var context = UpdateExecutionContextCache.Get <TEntity>(key);

            if (context != null)
            {
                return(context);
            }

            // Create
            var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction);

            context = CreateInternal <TEntity>(connection,
                                               tableName,
                                               where,
                                               dbFields,
                                               fields,
                                               hints,
                                               transaction,
                                               statementBuilder);

            // Add to cache
            UpdateExecutionContextCache.Add <TEntity>(key, context);

            // Return
            return(context);
        }