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


C# DbCommand.ExecuteScalarAsync方法代码示例

本文整理汇总了C#中System.Data.Common.DbCommand.ExecuteScalarAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DbCommand.ExecuteScalarAsync方法的具体用法?C# DbCommand.ExecuteScalarAsync怎么用?C# DbCommand.ExecuteScalarAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.Common.DbCommand的用法示例。


在下文中一共展示了DbCommand.ExecuteScalarAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteScalarAsync

        protected async Task<object> ExecuteScalarAsync(DbCommand command)
        {
            bool doClose = await InitializeConnectionAsync();
            initializeCommand(ref command);

            object ret = await command.ExecuteScalarAsync();

            if (doClose)
                Connection.Close();

            return ret;
        }
开发者ID:ChrisK91,项目名称:CWSRestart,代码行数:12,代码来源:Database.cs

示例2: DoExecuteScalarAsync

        /// <summary>
        /// 异步执行Command返回单值
        /// </summary>
        /// <param name="command">Command实例</param>
        /// <returns>单值</returns>
        private async Task<object> DoExecuteScalarAsync(DbCommand command)
        {
            ExceptionHelper.TrueThrow<ArgumentException>(command.CommandType == CommandType.TableDirect,
                Resource.ExecuteScalarNotSupportTableDirectException);

            using (DbContext context = await DbContext.GetContextAsync(this.name))
            {
                command.Connection = context.Connection;

                DoDbEvent(command, DbEventType.BeforeExecution);

                object returnValue = await command.ExecuteScalarAsync();

                if (command.CommandType != CommandType.Text)
                {
                    // 由于 SQL Server 在Stored Procedure和Function返回值处理方式上存在不同,因此增加了适应性修改
                    returnValue = (returnValue == null) ? command.Parameters[DefaultReturnValueParameterName].Value : returnValue;
                }

                DoDbEvent(command, DbEventType.AfterExecution);

                return returnValue;
            }
        }
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:29,代码来源:Database_Async.cs


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