当前位置: 首页>>代码示例>>C#>>正文


C# IDbConnection.ExecuteAsync方法代码示例

本文整理汇总了C#中IDbConnection.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.ExecuteAsync方法的具体用法?C# IDbConnection.ExecuteAsync怎么用?C# IDbConnection.ExecuteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDbConnection的用法示例。


在下文中一共展示了IDbConnection.ExecuteAsync方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InsertAsync

        public async Task<int> InsertAsync(
            IDbConnection connection,
            IDbTransaction transaction,
            int? commandTimeout,
            string tableName,
            string columnList,
            string parameterList,
            IEnumerable<PropertyInfo> keyProperties,
            object entityToInsert,
            bool autoIncrement)
        {
            var cmd = string.Format("insert into {0} ({1}) values ({2})", tableName, columnList, parameterList);

            await
                connection.ExecuteAsync(cmd, entityToInsert, transaction: transaction, commandTimeout: commandTimeout)
                    .ConfigureAwait(false);

            if (autoIncrement)
            {
                var r = connection.Query(
                    "select last_insert_rowid() id",
                    transaction: transaction,
                    commandTimeout: commandTimeout);
                var id = (int)r.First().id;
                if (keyProperties.Any())
                {
                    keyProperties.First().SetValue(entityToInsert, id, null);
                }

                return id;
            }

            return 0;
        }
开发者ID:AdaskoTheBeAsT,项目名称:dapper-for-AspnetIdentity,代码行数:34,代码来源:SQLiteAdapter.cs

示例2: ExtractedGis

        public static async Task<bool> ExtractedGis(IDbConnection connection, int featureId, string table)
        {
            table = table.ToUpper();

            foreach (var relatedTable in new[] {"FOCUSAREA", "COUNTY", "LANDOWNER", "SGMA"})
            {
                await connection.ExecuteAsync(string.Format("DELETE FROM [dbo].[{0}] ", relatedTable) +
                                              "WHERE [FeatureID] = @featureId AND " +
                                              "[FeatureClass] = @table", new
                                              {
                                                  featureId,
                                                  table
                                              });
            }

            if (table == "POLY")
            {
                await connection.ExecuteAsync("DELETE FROM [dbo].[STREAM] " +
                                              "WHERE [FeatureID] = @featureId", new
                                              {
                                                  featureId
                                              });
            }

            return await Task.Factory.StartNew(() => true);
        }
开发者ID:agrc,项目名称:wri-webapi,代码行数:26,代码来源:Delete.cs

示例3: UpdateOauthAccessToken

 /// <summary>
 /// Update accessToken only
 /// </summary>
 /// <param name="db"></param>
 /// <param name="accessToken"></param>
 /// <returns></returns>
 public async Task<bool> UpdateOauthAccessToken(IDbConnection db, int id,string access_token)
 {
     string sqlQuery = @"UPDATE oauth_access_token 
         SET
             access_token = @access_token
         WHERE
             id = @id";
     return 1 == await db.ExecuteAsync(sqlQuery, new { id, access_token });
 }
开发者ID:vietplayfuri,项目名称:Asp_Master,代码行数:15,代码来源:Account-Query.cs

示例4: UpdateUserCredential

 /// <summary>
 /// Update username and session only
 /// </summary>
 /// <param name="db"></param>
 /// <param name="userCredential"></param>
 /// <returns></returns>
 public async Task<bool> UpdateUserCredential(IDbConnection db, UserCredential userCredential)
 {
     string sqlQuery = @"UPDATE user_credential 
         SET
             username = @username,
             session = @session
         WHERE
             user_id = @user_id
         AND game_id = @game_id";
     return 1 == await db.ExecuteAsync(sqlQuery, userCredential);
 }
开发者ID:vietplayfuri,项目名称:Asp_Master,代码行数:17,代码来源:Account-Query.cs

示例5: SpatialFeature

        public static async Task<bool> SpatialFeature(IDbConnection connection, int featureId, string category, string table)
        {
            await connection.ExecuteAsync(string.Format("DELETE FROM [dbo].[{0}] ", table) +
                                          "WHERE [FeatureID] = @featureId AND " +
                                          "LOWER([TypeDescription]) = @category", new
                                          {
                                              featureId,
                                              category
                                          });

            return await Task.Factory.StartNew(()=>true);
        }
开发者ID:agrc,项目名称:wri-webapi,代码行数:12,代码来源:Delete.cs

示例6: Save

        public async Task Save(IDbConnection connection)
        {
            var transaction = connection.BeginTransaction();

            try
            {
                var stack = MergeStack();
                await
                    connection.ExecuteAsync(stack.Sql, stack.Parameters, transaction, null, CommandType.StoredProcedure);
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                transaction.Commit();
            }

        }
开发者ID:brentonmcs,项目名称:DapperContext,代码行数:21,代码来源:DapperContext.cs

示例7: InsertAsync

        public async Task<int> InsertAsync(
            IDbConnection connection,
            IDbTransaction transaction,
            int? commandTimeout,
            string tableName,
            string columnList,
            string parameterList,
            IEnumerable<PropertyInfo> keyProperties,
            object entityToInsert,
            bool autoIncrement)
        {
            var cmd = string.Format("insert into {0} ({1}) values ({2})", tableName, columnList, parameterList);

            await
                connection.ExecuteAsync(cmd, entityToInsert, transaction: transaction, commandTimeout: commandTimeout)
                    .ConfigureAwait(false);
            if (autoIncrement)
            {
                var r =
                    await
                    connection.QueryAsync<dynamic>(
                        "select scope_identity() id",
                        transaction: transaction,
                        commandTimeout: commandTimeout).ConfigureAwait(false);
                var id = (int)r.First().id;
                var keyProperty = keyProperties.FirstOrDefault();
                if (keyProperty != null)
                {
                    keyProperty.SetValue(entityToInsert, id, null);
                }

                return id;
            }

            // NOTE: would prefer to use IDENT_CURRENT('tablename') or IDENT_SCOPE but these are not available on SQLCE
            return 0;
        }
开发者ID:AdaskoTheBeAsT,项目名称:dapper-for-AspnetIdentity,代码行数:37,代码来源:SqlServerAdapter.cs

示例8: InsertAsync

        public async Task<int> InsertAsync(
            IDbConnection connection,
            IDbTransaction transaction,
            int? commandTimeout,
            string tableName,
            string columnList,
            string parameterList,
            IEnumerable<PropertyInfo> keyProperties,
            object entityToInsert,
            bool autoIncrement)
        {
            var cmd = string.Format("insert into {0} ({1}) values ({2})", tableName, columnList, parameterList);

            await
                connection.ExecuteAsync(cmd, entityToInsert, transaction: transaction, commandTimeout: commandTimeout)
                    .ConfigureAwait(false);
            if (autoIncrement)
            {
                // http://stackoverflow.com/questions/8517841/mysql-last-insert-id-connector-net
                var r =
                    await
                    connection.QueryAsync<ulong>(
                        "SELECT CAST(LAST_INSERT_ID() AS UNSIGNED INTEGER)",
                        transaction: transaction,
                        commandTimeout: commandTimeout).ConfigureAwait(false);
                var id = (int)(long)r.FirstOrDefault();
                var keyProperty = keyProperties.FirstOrDefault();
                if (keyProperty != null)
                {
                    keyProperty.SetValue(entityToInsert, id, null);
                }

                return id;
            }

            return 0;
        }
开发者ID:AdaskoTheBeAsT,项目名称:dapper-for-AspnetIdentity,代码行数:37,代码来源:MySqlAdapter.cs

示例9: LiteralReplacementDynamic

        private void LiteralReplacementDynamic(IDbConnection connection)
        {
            var args = new DynamicParameters();
            args.Add("id", 123);
            try { connection.ExecuteAsync("drop table literal2").Wait(); } catch { }
            connection.ExecuteAsync("create table literal2 (id int not null)").Wait();
            connection.ExecuteAsync("insert literal2 (id) values ({=id})", args).Wait();

            args = new DynamicParameters();
            args.Add("foo", 123);
            var count = connection.QueryAsync<int>("select count(1) from literal2 where id={=foo}", args).Result.Single();
            count.IsEqualTo(1);
        }
开发者ID:jpmarques,项目名称:dapper-dot-net,代码行数:13,代码来源:Tests.cs

示例10: LiteralReplacement

 private void LiteralReplacement(IDbConnection connection)
 {
     try { connection.ExecuteAsync("drop table literal1").Wait(); } catch { }
     connection.ExecuteAsync("create table literal1 (id int not null, foo int not null)").Wait();
     connection.ExecuteAsync("insert literal1 (id,foo) values ({=id}, @foo)", new { id = 123, foo = 456 }).Wait();
     var rows = new[] { new { id = 1, foo = 2 }, new { id = 3, foo = 4 } };
     connection.ExecuteAsync("insert literal1 (id,foo) values ({=id}, @foo)", rows).Wait();
     var count = connection.QueryAsync<int>("select count(1) from literal1 where id={=foo}", new { foo = 123 }).Result.Single();
     count.IsEqualTo(1);
     int sum = connection.QueryAsync<int>("select sum(id) + sum(foo) from literal1").Result.Single();
     sum.IsEqualTo(123 + 456 + 1 + 2 + 3 + 4);
 }
开发者ID:jpmarques,项目名称:dapper-dot-net,代码行数:12,代码来源:Tests.cs

示例11: SaveOneRateAsync

 private async Task<int> SaveOneRateAsync(IDbConnection connection, Rate rate)
 {
     try
     {
         return await connection.ExecuteAsync(
             "insert into Rates (BaseCurrency,Date,Holiday,SerializedRates) values (@BaseCurrency,@Date,@Holiday,@SerializedRates)",
             RateDatabaseModel.FromRate(rate));
     }
     catch (Exception ex)
     {
         _logger.Error(ex, "Failed to insert new exchange rate to database. Rate: {0}", JsonConvert.SerializeObject(rate));
         /*
            if repository can't save one rate - it will try to save other rates.
            a new rate can't be inserted, if the same data already inserted in other session
         */
     }
     return 0;
 }
开发者ID:andrewtsw,项目名称:Interesnee.BadBroker,代码行数:18,代码来源:RateRepository.cs

示例12: ExecuteAsync

 public async Task<int?> ExecuteAsync(IDbConnection connection, string type, object param = null)
 {
     return await connection.ExecuteAsync(_sql[type], param, null, 240);
 }
开发者ID:agrc,项目名称:wri-webapi,代码行数:4,代码来源:StandardQueries.cs

示例13: SpatialRow

        public static async Task<MessageWithStatus> SpatialRow(IDbConnection connection, IQuery queries, int id,
            FeatureActions[] actions, char retreatment, SqlGeometry geometry, string table, double size)
        {
            if (table == "POLY")
            {
                await connection.ExecuteAsync("UPDATE [dbo].[POLY]" +
                                              "SET [Shape] = @shape," +
                                              "[AreaSqMeters] = @size," +
                                              "[Retreatment] = @retreatment " +
                                              "WHERE [FeatureID] = @featureId", new
                                              {
                                                  shape = geometry,
                                                  retreatment,
                                                  featureId = id,
                                                  size
                                              });

                return await Task.Factory.StartNew(() => new MessageWithStatus
                {
                    Successful = true
                });
            }

            var action = actions.FirstOrDefault();
            if (action == null)
            {
                return await Task.Factory.StartNew(() => new MessageWithStatus()
                {
                    Successful = false,
                    Message = "Count not find action attributes."
                });
            }

            if (table == "LINE")
            {
                await connection.ExecuteAsync(string.Format("UPDATE [dbo].[{0}]", table) +
                                              "SET [FeatureSubTypeDescription] = @subtype," +
                                              "[FeatureSubTypeID] = (SELECT [FeatureSubTypeID] FROM [dbo].[LU_FEATURESUBTYPE] WHERE [FeatureSubTypeDescription] = @subType)," +
                                              "[ActionDescription] = @action," +
                                              "[ActionID] = (SELECT [ActionID] FROM [dbo].[LU_ACTION] WHERE [ActionDescription] = @action)," +
                                              "[Description] = @description," +
                                              "[LengthLnMeters] = @size," +
                                              "[Shape] = @shape " +
                                              "WHERE [FeatureID] = @featureId", new
                                              {
                                                  subType = action.Type,
                                                  action = action.Action,
                                                  shape = geometry,
                                                  size,
                                                  description = action.Description,
                                                  featureId = id
                                              });
            }
            else
            {
                await connection.ExecuteAsync(string.Format("UPDATE [dbo].[{0}]", table) +
                                               "SET [FeatureSubTypeDescription] = @subtype," +
                                               "[FeatureSubTypeID] = (SELECT [FeatureSubTypeID] FROM [dbo].[LU_FEATURESUBTYPE] WHERE [FeatureSubTypeDescription] = @subType)," +
                                               "[ActionDescription] = @action," +
                                               "[ActionID] = (SELECT [ActionID] FROM [dbo].[LU_ACTION] WHERE [ActionDescription] = @action)," +
                                               "[Description] = @description," +
                                               "[Shape] = @shape " +
                                               "WHERE [FeatureID] = @featureId", new
                                               {
                                                   subType = action.Type,
                                                   action = action.Action,
                                                   shape = geometry,
                                                   description = action.Description,
                                                   featureId = id
                                               }); 
            }

            return await Task.Factory.StartNew(() => new MessageWithStatus()
            {
                Successful = true
            });
        }
开发者ID:agrc,项目名称:wri-webapi,代码行数:77,代码来源:Update.cs

示例14: Actions

        public static async Task<bool> Actions(IDbConnection connection, int featureId)
        {
            var actions = await connection.QueryAsync<int>("SELECT [AreaActionId] " +
                                                           "FROM [dbo].[AREAACTION] WHERE " +
                                                           "[FeatureID] = @featureId", new
                                                           {
                                                               featureId
                                                           });
            actions = actions.ToList();

            if (!actions.Any())
            {
                return await Task.Factory.StartNew(()=>true);
            }

            var treatments = await connection.QueryAsync<int>("SELECT [AreaTreatmentID] " +
                                                              "FROM [dbo].[AREATREATMENT] WHERE " +
                                                              "[AreaActionID] IN @actions", new
                                                              {
                                                                  actions
                                                              });

            treatments = treatments.ToList();

            if (!treatments.Any())
            {
                return await Task.Factory.StartNew(() => true);
            }

            await connection.ExecuteAsync("DELETE FROM [dbo].[AREAHERBICIDE] WHERE " +
                                          "[AreaTreatmentID] IN @treatments", new
                                          {
                                              treatments
                                          });

            await connection.ExecuteAsync("DELETE FROM [dbo].[AREATREATMENT] WHERE " +
                                          "[AreaTreatmentID] IN @treatments", new
                                          {
                                              treatments
                                          });

            await connection.ExecuteAsync("DELETE FROM [dbo].[AREAACTION] WHERE " +
                                          "[AreaActionID] IN @actions", new
                                          {
                                              actions
                                          });

            return await Task.Factory.StartNew(() => true);
        }
开发者ID:agrc,项目名称:wri-webapi,代码行数:49,代码来源:Delete.cs


注:本文中的IDbConnection.ExecuteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。