本文整理汇总了C#中System.Data.SqlClient.SqlConnection.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SqlConnection.ExecuteAsync方法的具体用法?C# SqlConnection.ExecuteAsync怎么用?C# SqlConnection.ExecuteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlConnection
的用法示例。
在下文中一共展示了SqlConnection.ExecuteAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommandFooTests
public CommandFooTests()
{
barCmd = new Command<Bar>();
cmd = new Command<Foo>()
.ConfigureField(o => o.Bar, c => c.IsMapped = false)
.ConfigureField(o => o.Bars, c => c.IsMapped = false);
con = new SqlConnection(ConfigurationManager.ConnectionStrings["Db"].ConnectionString);
con.Open();
con.ExecuteAsync("truncate table dbo.Foo").Wait();
con.ExecuteAsync("truncate table dbo.Bar").Wait();
}
示例2: CommandSecureTests
public CommandSecureTests()
{
barCmd = new Command<Bar>();
cmd = new Command<Secure>()
.ConfigureAllFields(c => c.Secure(), c => c.Name != "Id")
.ConfigureField(o => o.Bar, c => c.IsMapped = false)
.ConfigureField(o => o.Bars, c => c.IsMapped = false);
con = new SqlConnection(ConfigurationManager.ConnectionStrings["Db"].ConnectionString);
con.Open();
con.ExecuteAsync("truncate table dbo.Secure").Wait();
con.ExecuteAsync("truncate table dbo.Bar").Wait();
}
示例3: ExecuteTests
public ExecuteTests()
{
sql = new SqlConnection(ConfigurationManager.ConnectionStrings["Db"].ConnectionString);
sql.Open();
sql.ExecuteAsync("truncate table dbo.Foo").Wait();
}
示例4: DropDatabase
internal static async Task DropDatabase(string connectionString, string databaseName)
{
using (var conn = new SqlConnection(connectionString))
{
await conn.OpenAsync();
await conn.ExecuteAsync(string.Format("DROP DATABASE [{0}]", databaseName));
}
}
示例5: Insert
public async Task Insert(Guid id, ProposalEditModel item)
{
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
var proposal = connection.ExecuteAsync("insert into Proposals(Id, Status, CreatedBy, CreatedOn, UpdatedOn) values(@id, 0, @createdBy, @now, @now);", new { id = id, createdBy = "user", now = DateTime.UtcNow }, transaction);
var students = connection.ExecuteAsync("insert into Proposals_2_Students(ProposalId, StudentId) values(@proposalId, @studentId);", item.Students.Select(s => new { proposalId = id, studentId = s }), transaction);
var actions = connection.ExecuteAsync("insert into Proposals_2_Actions(ProposalId, ActionId, [Values]) values(@proposalId, @actionId, @values);", item.Actions.Select(a => new { proposalId = id, actionId = a.Id, values = FieldsXmlHelpers.ValuesToXml(a.FieldValues) }), transaction);
var reasons = connection.ExecuteAsync("insert into Proposals_2_Reasons(ProposalId, ReasonId, [Values]) values(@proposalId, @reasonId, @values);", item.Reasons.Select(r => new { proposalId = id, reasonId = r.Id, values = FieldsXmlHelpers.ValuesToXml(r.FieldValues) }), transaction);
await Task.WhenAll(proposal, students, actions, reasons);
transaction.Commit();
}
}
}
示例6: SaveDueDate
public async Task SaveDueDate(int issueId, DateTime? dueDate, int userId)
{
using (var con = new SqlConnection(ConnectionString))
{
con.Open();
await con.ExecuteAsync("UPDATE Issue SET [email protected],[email protected],[email protected] WHERE [email protected]",
new { @modifiedDate = DateTime.Now, issueId, dueDate, userId });
}
}
示例7: AddIssueMemberRecord
private async Task AddIssueMemberRecord(int issueId, int userId, string type)
{
using (var con = new SqlConnection(ConnectionString))
{
con.Open();
await con.ExecuteAsync("INSERT INTO IssueMember(IssueID,MemberID,RelationType,CreatedDate,CreatedByID) VALUES(@id,@userId,@type,@dt,@userId);",
new { @id = issueId, @userId = userId, @type = type, @dt = DateTime.Now, });
}
}
示例8: DeleteIssueMemberRecord
private async Task DeleteIssueMemberRecord(int issueId, int userId, string type)
{
using (var con = new SqlConnection(ConnectionString))
{
con.Open();
await con.ExecuteAsync("DELETE FROM IssueMember WHERE [email protected] AND [email protected] and [email protected]",
new { @id = issueId, @userId = userId, @type = type });
}
}
示例9: DeleteTeamMemberInvitation
public async Task DeleteTeamMemberInvitation(int id)
{
var q = @"DELETE FROM TeamMemberRequest WHERE ID = @id";
using (var con = new SqlConnection(ConnectionString))
{
con.Open();
await con.ExecuteAsync(q, new { @id = id });
}
}
示例10: AddSubreddit
public async Task<string> AddSubreddit( Subreddit sub ) {
sub.SubName = sub.SubName;
using ( SqlConnection conn = new SqlConnection( connstring ) ) {
string query = "insert into Subreddits (SubName,Active) values (@SubName,@Active)";
await conn.ExecuteAsync( query, new { sub.SubName, sub.Active } );
string result = "Success";
return result;
}
}
示例11: SetDefaultTeam
public async Task SetDefaultTeam(int userId, int teamId)
{
var q = @"UPDATE [User] SET [email protected] WHERE [email protected]";
using (var con = new SqlConnection(ConnectionString))
{
con.Open();
await con.ExecuteAsync(q, new { @userId = userId, @teamId = teamId });
}
}
示例12: QueryTests
public QueryTests()
{
sql = new SqlConnection(ConfigurationManager.ConnectionStrings["Db"].ConnectionString);
sql.Open();
sql.ExecuteAsync("truncate table dbo.Foo").Wait();
sql.ExecuteAsync(
"insert into Foo (Guid, Int, DateTime2, DateTimeOffset) values (@Guid, @Int, @DateTime2, @DateTimeOffset)",
Enumerable.Range(0, 1000).Select(i =>
new
{
Guid = Guid.NewGuid(),
Int = i,
DateTime2 = DateTime.UtcNow,
DateTimeOffset = DateTimeOffset.Now,
}
)
).Wait();
}
示例13: TomSecureTests
public TomSecureTests()
{
db = new Db("Db");
using (var cx = new SqlConnection(db.ConnectionString))
{
cx.Open();
cx.ExecuteAsync("truncate table dbo.Secure").Wait();
}
}
示例14: UpdateLastLoginTime
public async Task UpdateLastLoginTime(int userId)
{
var q = @"UPDATE [User] SET [email protected] WHERE [email protected]";
using (var con = new SqlConnection(ConnectionString))
{
con.Open();
var com = await con.ExecuteAsync(q, new { @date = DateTime.UtcNow,userId });
}
}
示例15: ReplaceAsync
public async Task ReplaceAsync(Blog blog)
{
var propertyContainer = SqlHelpers.ParseProperties(blog);
var sqlPairs = string.Join(", ", propertyContainer.PairedProperties);
var sql = $"UPDATE [Blog] SET {sqlPairs};";
using(var connection = new SqlConnection(ConnectionString))
{
await connection.ExecuteAsync(sql, blog);
}
}