本文整理汇总了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;
}
}
示例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;
}
}
示例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;
}
}
示例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();
}
}
示例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;
}
}
示例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;
}
}
示例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();
}
}
示例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;
}
}