本文整理汇总了C#中System.Data.SQLite.SQLiteConnection.QueryAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.QueryAsync方法的具体用法?C# SQLiteConnection.QueryAsync怎么用?C# SQLiteConnection.QueryAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SQLite.SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.QueryAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUserMessages
public async Task<DataPage<UserMessage>> GetUserMessages(string userLogin, int pageNumber, int pageSize)
{
ValidatePagination(pageNumber, pageSize);
using (var conn = new SQLiteConnection(_connectionString))
{
await conn.OpenAsync().ConfigureAwait(false);
if (await conn.ExecuteScalarAsync<int>("select count(*) from [User] where Login = @userLogin", new { userLogin }).ConfigureAwait(false) == 0)
return new DataPage<UserMessage>(pageNumber, pageSize, 0, null); //not found
int count = await conn.ExecuteScalarAsync<int>("select count(*) from [Message] m join [User] u on m.UserId=u.UserId where u.Login = @userLogin", new {userLogin}).ConfigureAwait(false);
string q = "select u.Login as UserLogin, m.Text, m.Created from [Message] m join [User] u on m.UserId=u.UserId where u.Login = @userLogin order by m.Created";
object prms;
if (pageSize == -1)
prms = new { userLogin };
else
{
q += " limit @size offset @skip";
prms = new { userLogin, size = pageSize, skip = (pageNumber - 1) * pageSize };
}
return
new DataPage<UserMessage>(pageNumber, pageSize, count,
(await conn.QueryAsync<UserMessage>(q, prms)).ToList());
}
}
示例2: GetUsers
public async Task<DataPage<UserInfo>> GetUsers(int pageNumber, int pageSize)
{
ValidatePagination(pageNumber, pageSize);
using (var conn = new SQLiteConnection(_connectionString))
{
await conn.OpenAsync().ConfigureAwait(false);
int count = await conn.ExecuteScalarAsync<int>("select count(*) from [User]").ConfigureAwait(false);
string q = "select [Login] as UserLogin, Display as DisplayName, Created from [User] order by [Login]";
object prms;
if (pageSize == -1)
prms = null;
else
{
q += " limit @size offset @skip";
prms = new { size = pageSize, skip = (pageNumber - 1) * pageSize };
}
return
new DataPage<UserInfo>(pageNumber, pageSize, count,
(await conn.QueryAsync<UserInfo>(q, prms).ConfigureAwait(false)).ToList());
}
}