本文整理汇总了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;
}
示例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);
}
示例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 });
}
示例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);
}
示例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);
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例12: ExecuteAsync
public async Task<int?> ExecuteAsync(IDbConnection connection, string type, object param = null)
{
return await connection.ExecuteAsync(_sql[type], param, null, 240);
}
示例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
});
}
示例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);
}