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


C# Columns.Any方法代码示例

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


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

示例1: ConfigureCreateCommand

        /// <summary>
        /// 添加数据。
        /// </summary>
        /// <param name="command">SQL命令执行对象</param>
        /// <param name="tableName">表名称</param>
        /// <param name="allColumns">所有列信息</param>
        /// <returns>命令执行对象</returns>
        protected override void ConfigureCreateCommand(DbCommand command, string tableName, Columns allColumns)
        {
            var index = 1;
            var insertColumns = allColumns.Where(c => !c.IsIdentity);
            var commandTextBuilder = new StringBuilder();

            commandTextBuilder.AppendFormat("INSERT INTO {0} (", this.GetSafeTableName(tableName));

            foreach (var column in insertColumns)
            {
                commandTextBuilder.AppendFormat(index++ == insertColumns.Count() ? "\"{0}\"" : "\"{0}\",", column.Name);
            }

            commandTextBuilder.AppendFormat(") VALUES (");

            index = 1;
            foreach (var item in insertColumns)
            {
                var format = index++ == insertColumns.Count() ? ":{0}" : ":{0}, ";

                commandTextBuilder.AppendFormat(format, item.Name);
                command.AddParameter($":{item.Name}", item.Value, this._dbTypeResolve.GetDbType(item.DataType));
            }

            commandTextBuilder.Append(")");

            if (allColumns.Any(c => c.IsIdentity))
            {
                var identity = allColumns.First(i => i.IsIdentity);

                commandTextBuilder.AppendFormat(";SELECT currval(pg_get_serial_sequence('{0}', '{1}'));", this.GetSafeTableName(tableName), identity.Name);
            }

            command.CommandType = CommandType.Text;
            command.CommandText = commandTextBuilder.ToString();

            this.RecordCommandInfo("添加记录", command);
        }
开发者ID:fenglinz,项目名称:Sparrow,代码行数:45,代码来源:PostgreSQLDynamicQueryProvider.cs

示例2: ConfigureCreateCommand

        /// <summary>
        /// 添加数据。
        /// </summary>
        /// <param name="command">SQL命令执行对象</param>
        /// <param name="tableName">表名称</param>
        /// <param name="allColumns">所有列信息</param>
        /// <returns>命令执行对象</returns>
        protected override void ConfigureCreateCommand(DbCommand command, string tableName, Columns allColumns)
        {
            var index = 1;
            var insertColumns = allColumns.Where(c => !c.IsIdentity);
            var commandTextBuilder = new StringBuilder();

            commandTextBuilder.AppendFormat("INSERT INTO {0} (", this.GetSafeTableName(tableName));

            foreach (var column in insertColumns)
            {
                commandTextBuilder.AppendFormat(index++ == insertColumns.Count() ? "[{0}]" : "[{0}],", column.Name);
            }

            commandTextBuilder.AppendFormat(") VALUES (");

            index = 1;
            foreach (var item in insertColumns)
            {
                var format = index++ == insertColumns.Count() ? "@{0}" : "@{0}, ";

                commandTextBuilder.AppendFormat(format, item.Name);
                command.AddParameter($"@{item.Name}", item.Value);
            }

            commandTextBuilder.Append(")");

            if (allColumns.Any(c => c.IsIdentity))
            {
                commandTextBuilder.Append(";SELECT @@IDENTITY;");
            }

            command.CommandType = CommandType.Text;
            command.CommandText = commandTextBuilder.ToString();

            this.RecordCommandInfo("添加记录", command);
        }
开发者ID:fenglinz,项目名称:Sparrow,代码行数:43,代码来源:MSSQLDynamicQueryProvider.cs


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