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


C# IDbConnection.QueryAsync方法代码示例

本文整理汇总了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());
        }
开发者ID:armory09,项目名称:ConstosoUniversityMVCwithDapper,代码行数:29,代码来源:DepartmentController.cs

示例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();
 }
开发者ID:vietplayfuri,项目名称:Asp_Master,代码行数:8,代码来源:Account-Query.cs

示例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());
 }
开发者ID:vietplayfuri,项目名称:Asp_Master,代码行数:9,代码来源:Account-Query.cs

示例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();
 }
开发者ID:vietplayfuri,项目名称:Asp_Master,代码行数:10,代码来源:Account-Query.cs

示例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());
        }
开发者ID:armory09,项目名称:ConstosoUniversityMVCwithDapper,代码行数:18,代码来源:DepartmentController.cs

示例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;
        }
开发者ID:AdaskoTheBeAsT,项目名称:dapper-for-AspnetIdentity,代码行数:37,代码来源:MySqlAdapter.cs

示例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;
        }
开发者ID:AdaskoTheBeAsT,项目名称:dapper-for-AspnetIdentity,代码行数:37,代码来源:SqlServerAdapter.cs

示例8: FeatureClassQueryAsync

 public async Task<IEnumerable<int?>> FeatureClassQueryAsync(IDbConnection connection, string featureClass,
     object param = null)
 {
     return await connection.QueryAsync<int?>(_sql[featureClass], param);
 }
开发者ID:agrc,项目名称:wri-webapi,代码行数:5,代码来源:StandardQueries.cs

示例9: OverlapQueryAsync

 public async Task<IEnumerable<int?>> OverlapQueryAsync(IDbConnection connection, object param = null)
 {
     return await connection.QueryAsync<int?>(_sql["Overlap"], param);
 }
开发者ID:agrc,项目名称:wri-webapi,代码行数:4,代码来源:StandardQueries.cs

示例10: ContributorQueryAsync

 public async Task<IEnumerable<int>> ContributorQueryAsync(IDbConnection connection, object param = null)
 {
     return await connection.QueryAsync<int>(_sql["Contributor"], param);
 }
开发者ID:agrc,项目名称:wri-webapi,代码行数:4,代码来源:StandardQueries.cs

示例11: UserQueryAsync

 public async Task<IEnumerable<User>> UserQueryAsync(IDbConnection connection, object param = null)
 {
     return await connection.QueryAsync<User>(_sql["User"], param);
 }
开发者ID:agrc,项目名称:wri-webapi,代码行数:4,代码来源:StandardQueries.cs

示例12: ProjectMinimalQueryAsync

 public async Task<IEnumerable<Project>> ProjectMinimalQueryAsync(IDbConnection connection, object param = null)
 {
     return await connection.QueryAsync<Project>(_sql["ProjectMinimal"], param);
 }
开发者ID:agrc,项目名称:wri-webapi,代码行数:4,代码来源:StandardQueries.cs

示例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();
            }
        }
开发者ID:n1ghtmare,项目名称:Kauntr,代码行数:15,代码来源:AccountRepository.cs

示例14: TreatmentQueryAsync

 public async Task<IEnumerable<int?>> TreatmentQueryAsync(IDbConnection connection, object param = null)
 {
     return await connection.QueryAsync<int?>(_sql["Treatment"], param);
 }
开发者ID:agrc,项目名称:wri-webapi,代码行数:4,代码来源:StandardQueries.cs

示例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;
        }
开发者ID:agrc,项目名称:wri-webapi,代码行数:20,代码来源:StandardQueries.cs


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