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


C# MySqlConnection.QueryAsync方法代码示例

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


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

示例1: GetByNameAsync

        public async Task<Account> GetByNameAsync(string address)
        {
            using (var sqlConnection = new MySqlConnection(_connectionString))
            {
                sqlConnection.Open();

                var accounts = await sqlConnection.QueryAsync<Account>("SELECT * FROM hm_accounts WHERE accountaddress = @accountaddress", new
                    {
                        accountaddress = address
                    });

                var account = accounts.SingleOrDefault();

                return account;
            }
        }
开发者ID:hmailserver,项目名称:hmailserver-net,代码行数:16,代码来源:AccountRepository.cs

示例2: GetByIdAsync

        public async Task<Account> GetByIdAsync(long id)
        {
            using (var sqlConnection = new MySqlConnection(_connectionString))
            {
                sqlConnection.Open();

                var accounts = await sqlConnection.QueryAsync<Account>("SELECT * FROM hm_accounts WHERE accountid = @accountid", new
                {
                    accountid = id
                });

                var account = accounts.SingleOrDefault();

                return account;
            }
        }
开发者ID:hmailserver,项目名称:hmailserver-net,代码行数:16,代码来源:AccountRepository.cs

示例3: GetAll

        public async Task<IEnumerable<UserDto>> GetAll()
        {
            using (var connection = new MySqlConnection(ConfigurationManager.ConnectionStrings[Constants.ConnectionStringName].ConnectionString))
            {
                await connection.OpenAsync();

                // Read all the userId's and userName's from the database, but don't send their password hashes.
                var result = await connection.QueryAsync<UserDto>(@"
SELECT 
UserId,
UserName
FROM 
User
");
                return result;
            }
        }
开发者ID:heptadassembly,项目名称:DemoApp,代码行数:17,代码来源:UserController.cs

示例4: GetFolders

        public async Task<List<Folder>> GetFolders(long accountId)
        {
            using (var sqlConnection = new MySqlConnection(_connectionString))
            {
                sqlConnection.Open();

                var folders =
                    await
                        sqlConnection.QueryAsync<Folder>(
                            "SELECT * FROM hm_imapfolders WHERE folderaccountid = @folderaccountid",
                            new
                            {
                                folderaccountid = accountId,
                            });

                return folders.ToList();
            }
        }
开发者ID:hmailserver,项目名称:hmailserver-net,代码行数:18,代码来源:FolderRepository.cs

示例5: GetAll

        public async Task<IEnumerable<DocumentEntity>> GetAll()
        {
            using (var connection = new MySqlConnection(ConfigurationManager.ConnectionStrings[Constants.ConnectionStringName].ConnectionString))
            {
                await connection.OpenAsync();

                // Read all the documents from the database.
                var result = await connection.QueryAsync<DocumentEntity>(@"
SELECT 
DocumentId,
Title, 
Body,
CreatedWhen,
CreatedBy
FROM 
Document;
");

                return result;
            }
        }
开发者ID:heptadassembly,项目名称:DemoApp,代码行数:21,代码来源:DocumentController.cs

示例6: ValidatePasswordAsync

        public async Task<Account> ValidatePasswordAsync(string username, string password)
        {
            using (var sqlConnection = new MySqlConnection(_connectionString))
            {
                sqlConnection.Open();

                var accounts = await sqlConnection.QueryAsync<Account>("SELECT * FROM hm_accounts WHERE accountaddress = @accountaddress", new
                {
                    accountaddress = username
                });

                var account = accounts.SingleOrDefault();

                if (account == null)
                    return null;

                // TODO: Support old hashing methods.
                var salter = new Salter();
                if (salter.ValidateHash(password, account.Password))
                    return account;

                return null;
            }
        }
开发者ID:hmailserver,项目名称:hmailserver-net,代码行数:24,代码来源:AccountRepository.cs

示例7: GetMessages

        public async Task<List<Message>> GetMessages(long accountId, long folderId)
        {
            using (var sqlConnection = new MySqlConnection(_connectionString))
            {
                sqlConnection.Open();

                var messages =
                    await
                        sqlConnection.QueryAsync<Message>(
                            "SELECT * FROM hm_messages WHERE messageaccountid = @messageaccountid AND messagefolderid = @messagefolderid",
                            new
                            {
                                messageaccountid = accountId,
                                messagefolderid = folderId
                            });

                return messages.ToList();
            }
        }
开发者ID:hmailserver,项目名称:hmailserver-net,代码行数:19,代码来源:MessageRepository.cs

示例8: GetMessageToDeliverAsync

        public async Task<Message> GetMessageToDeliverAsync()
        {
            using (var sqlConnection = new MySqlConnection(_connectionString))
            {
                sqlConnection.Open();

                // TODO: MessageNextTryTime should be included in SQL

                var messages =
                    await sqlConnection.QueryAsync<Message>("SELECT * FROM hm_messages WHERE messagetype = 1 AND messagelocked = 0 LIMIT 1");
                var message = messages.SingleOrDefault();

                if (message != null)
                {
                    var recipients = await sqlConnection.QueryAsync<Recipient>(
                                            "SELECT * FROM hm_messagerecipients where recipientmessageid = @recipientmessageid",
                                                new
                                                {
                                                    recipientmessageid = message.Id
                                                });

                    foreach (var recipient in recipients)
                        message.Recipients.Add(recipient);
                }

                return message;
            }
        }
开发者ID:hmailserver,项目名称:hmailserver-net,代码行数:28,代码来源:MessageRepository.cs


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