當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。