本文整理汇总了C#中IDbConnection.QueryAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.QueryAsync方法的具体用法?C# IDbConnection.QueryAsync怎么用?C# IDbConnection.QueryAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbConnection
的用法示例。
在下文中一共展示了IDbConnection.QueryAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Details
// GET: Department/Details/5
public async Task<ActionResult> Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
_query.Append("SELECT d.*, i.LastName, i.FirstMidName FROM dbo.Department d " +
"INNER JOIN dbo.Instructor i ON i.InstructorId = d.InstructorId " +
"WHERE d.DepartmentId = @id");
_conection = Connect.Open();
var departmentLst = await _conection.QueryAsync<Department, Instructor, Department>(_query.ToString(),
((department, instructor) =>
{
department.Administrators = instructor;
return department;
}), new {id},
splitOn: "LastName");
_query.Clear();
if (departmentLst == null)
{
return HttpNotFound();
}
return View(departmentLst.FirstOrDefault());
}
示例2: CreateOauthAccessToken
public async Task<int> CreateOauthAccessToken(IDbConnection db, OauthAccessToken oauthAccessToken)
{
string sqlQuery = @"INSERT INTO oauth_access_token(service, identity, access_token, game_id)
VALUES (@service, @identity, @access_token, @game_id)
RETURNING id";
var obj = await db.QueryAsync<int>(sqlQuery, oauthAccessToken);
return obj.FirstOrDefault();
}
示例3: GetOauthAccessToken
public async Task<Result<OauthAccessToken>> GetOauthAccessToken(IDbConnection db, string service, string identity, int game_id)
{
service = service.ToLower();
string sqlString = @"SELECT *
FROM oauth_access_token
WHERE lower(service) [email protected] and [email protected] and game_id = @game_id";
var OAuth = await db.QueryAsync<OauthAccessToken>(sqlString, new { service, identity, game_id });
return Result<OauthAccessToken>.Make(OAuth.FirstOrDefault());
}
示例4: CreateUserCredential
public async Task<int> CreateUserCredential(IDbConnection db, UserCredential userCredential)
{
string sqlQuery = @"INSERT INTO user_credential
(user_id, game_id, username, session)
VALUES
(@user_id, @game_id, @username, @session)
RETURNING id";
var obj = await db.QueryAsync<int>(sqlQuery, userCredential);
return obj.FirstOrDefault();
}
示例5: Index
// GET: Department
public async Task<ActionResult> Index()
{
_conection = Connect.Open();
_query.Append("SELECT d.*, i.FirstMidName, i.LastName FROM dbo.Department d " +
"INNER JOIN dbo.Instructor i ON i.InstructorId = d.InstructorId");
var departments = await _conection.QueryAsync<Department, Instructor, Department>(_query.ToString(),
((department, instructor) =>
{
department.Administrators = instructor;
return department;
}), splitOn: "FirstMidName");
_query.Clear();
return View(departments.ToList());
}
示例6: InsertAsync
public async Task<int> InsertAsync(
IDbConnection connection,
IDbTransaction transaction,
int? commandTimeout,
string tableName,
string columnList,
string parameterList,
IEnumerable<PropertyInfo> keyProperties,
object entityToInsert,
bool autoIncrement)
{
var cmd = string.Format("insert into {0} ({1}) values ({2})", tableName, columnList, parameterList);
await
connection.ExecuteAsync(cmd, entityToInsert, transaction: transaction, commandTimeout: commandTimeout)
.ConfigureAwait(false);
if (autoIncrement)
{
// http://stackoverflow.com/questions/8517841/mysql-last-insert-id-connector-net
var r =
await
connection.QueryAsync<ulong>(
"SELECT CAST(LAST_INSERT_ID() AS UNSIGNED INTEGER)",
transaction: transaction,
commandTimeout: commandTimeout).ConfigureAwait(false);
var id = (int)(long)r.FirstOrDefault();
var keyProperty = keyProperties.FirstOrDefault();
if (keyProperty != null)
{
keyProperty.SetValue(entityToInsert, id, null);
}
return id;
}
return 0;
}
示例7: InsertAsync
public async Task<int> InsertAsync(
IDbConnection connection,
IDbTransaction transaction,
int? commandTimeout,
string tableName,
string columnList,
string parameterList,
IEnumerable<PropertyInfo> keyProperties,
object entityToInsert,
bool autoIncrement)
{
var cmd = string.Format("insert into {0} ({1}) values ({2})", tableName, columnList, parameterList);
await
connection.ExecuteAsync(cmd, entityToInsert, transaction: transaction, commandTimeout: commandTimeout)
.ConfigureAwait(false);
if (autoIncrement)
{
var r =
await
connection.QueryAsync<dynamic>(
"select scope_identity() id",
transaction: transaction,
commandTimeout: commandTimeout).ConfigureAwait(false);
var id = (int)r.First().id;
var keyProperty = keyProperties.FirstOrDefault();
if (keyProperty != null)
{
keyProperty.SetValue(entityToInsert, id, null);
}
return id;
}
// NOTE: would prefer to use IDENT_CURRENT('tablename') or IDENT_SCOPE but these are not available on SQLCE
return 0;
}
示例8: FeatureClassQueryAsync
public async Task<IEnumerable<int?>> FeatureClassQueryAsync(IDbConnection connection, string featureClass,
object param = null)
{
return await connection.QueryAsync<int?>(_sql[featureClass], param);
}
示例9: OverlapQueryAsync
public async Task<IEnumerable<int?>> OverlapQueryAsync(IDbConnection connection, object param = null)
{
return await connection.QueryAsync<int?>(_sql["Overlap"], param);
}
示例10: ContributorQueryAsync
public async Task<IEnumerable<int>> ContributorQueryAsync(IDbConnection connection, object param = null)
{
return await connection.QueryAsync<int>(_sql["Contributor"], param);
}
示例11: UserQueryAsync
public async Task<IEnumerable<User>> UserQueryAsync(IDbConnection connection, object param = null)
{
return await connection.QueryAsync<User>(_sql["User"], param);
}
示例12: ProjectMinimalQueryAsync
public async Task<IEnumerable<Project>> ProjectMinimalQueryAsync(IDbConnection connection, object param = null)
{
return await connection.QueryAsync<Project>(_sql["ProjectMinimal"], param);
}
示例13: CreateAccountLoginsAsync
private static async Task CreateAccountLoginsAsync(Account account, IDbConnection connection) {
const string query =
"INSERT INTO AccountLogins (AccountId, ProviderUserId, ProviderName) " +
"OUTPUT INSERTED.Id " +
"VALUES (@AccountId, @ProviderUserId, @ProviderName)";
foreach (AccountLogin accountLogin in account.AccountLogins) {
var loginParams = new {
AccountId = account.Id,
accountLogin.ProviderUserId,
accountLogin.ProviderName
};
accountLogin.Id = (await connection.QueryAsync<Guid>(query, loginParams)).Single();
}
}
示例14: TreatmentQueryAsync
public async Task<IEnumerable<int?>> TreatmentQueryAsync(IDbConnection connection, object param = null)
{
return await connection.QueryAsync<int?>(_sql["Treatment"], param);
}
示例15: ProjectQueryAsync
public async Task<Project> ProjectQueryAsync(IDbConnection connection, object param = null)
{
var projects = await connection.QueryAsync<Project>(_sql["Project"], param);
var project = projects.FirstOrDefault();
if (project == null)
{
return null;
}
var records = await ProjectRollupQueryAsync(connection, param);
project.County = records.Where(x => x.Origin == "county");
project.FocusArea = records.Where(x => x.Origin == "focus");
project.SageGrouse = records.Where(x => x.Origin == "sgma");
project.LandOwnership = records.Where(x => x.Origin == "owner");
project.LandOwnership = records.Where(x => x.Origin == "owner");
return project;
}