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


C# SqlConnection.ExecuteAsync方法代码示例

本文整理汇总了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();
        }
开发者ID:jeremycook,项目名称:Tom,代码行数:13,代码来源:CommandFooTests.cs

示例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();
        }
开发者ID:jeremycook,项目名称:Tom,代码行数:14,代码来源:CommandSecureTests.cs

示例3: ExecuteTests

        public ExecuteTests()
        {
            sql = new SqlConnection(ConfigurationManager.ConnectionStrings["Db"].ConnectionString);
            sql.Open();

            sql.ExecuteAsync("truncate table dbo.Foo").Wait();
        }
开发者ID:jeremycook,项目名称:Tom,代码行数:7,代码来源:ExecuteTests.cs

示例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));
     }
 }
开发者ID:diijon,项目名称:EFDDD,代码行数:8,代码来源:InternalHelpers.cs

示例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();
                }
            }
        }
开发者ID:kutynko,项目名称:contingent,代码行数:17,代码来源:ProposalsRepository.cs

示例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 });
     }
 }
开发者ID:kshyju,项目名称:ProjectPlanningTool,代码行数:9,代码来源:IIssueRepository.cs

示例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, });
     }
 }
开发者ID:kshyju,项目名称:ProjectPlanningTool,代码行数:9,代码来源:IIssueRepository.cs

示例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 });
     }
 }
开发者ID:kshyju,项目名称:ProjectPlanningTool,代码行数:9,代码来源:IIssueRepository.cs

示例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 });
     }
 }
开发者ID:kshyju,项目名称:ProjectPlanningTool,代码行数:9,代码来源:TeamRepository.cs

示例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;
     }
 }
开发者ID:CrustyJew,项目名称:SnooNotes,代码行数:9,代码来源:SubredditDAL.cs

示例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 });
     }
 }
开发者ID:kshyju,项目名称:ProjectPlanningTool,代码行数:9,代码来源:IUserRepository.cs

示例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();
        }
开发者ID:jeremycook,项目名称:Tom,代码行数:19,代码来源:QueryTests.cs

示例13: TomSecureTests

        public TomSecureTests()
        {
            db = new Db("Db");

            using (var cx = new SqlConnection(db.ConnectionString))
            {
                cx.Open();
                cx.ExecuteAsync("truncate table dbo.Secure").Wait();
            }
        }
开发者ID:jeremycook,项目名称:Tom,代码行数:10,代码来源:TomSecureTests.cs

示例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 });
         
     }
 }
开发者ID:kshyju,项目名称:ProjectPlanningTool,代码行数:10,代码来源:IUserRepository.cs

示例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);
            }
        }
开发者ID:kspearrin,项目名称:NPress,代码行数:12,代码来源:BlogRepository.cs


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