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


C# IQueryContext.GetTablePrimaryKey方法代码示例

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


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

示例1: Evaluate

            public override ITable Evaluate(IQueryContext context)
            {
                if (!context.UserCanAlterTable(TableName))
                    throw new InvalidAccessException(TableName);

                var table = context.GetTable(TableName);
                if (table == null)
                    throw new ObjectNotFoundException(TableName);

                var tableInfo = table.TableInfo;
                var newTableInfo = new TableInfo(tableInfo.TableName);

                var checker = ColumnChecker.Default(context, TableName);

                bool tableAltered = false;
                bool markDropped = false;

                for (int n = 0; n < tableInfo.ColumnCount; ++n) {
                    var column = tableInfo[n];

                    string columnName = column.ColumnName;
                    var columnType = column.ColumnType;
                    var defaultExpression = column.DefaultExpression;

                    if (Action.ActionType == AlterTableActionType.SetDefault &&
                        CheckColumnNamesMatch(context, ((SetDefaultAction) Action).ColumnName, columnName)) {
                        var exp = ((SetDefaultAction) Action).DefaultExpression;
                        exp = checker.CheckExpression(exp);
                        defaultExpression = exp;
                        tableAltered = true;
                    } else if (Action.ActionType == AlterTableActionType.DropDefault &&
                               CheckColumnNamesMatch(context, ((DropDefaultAction) Action).ColumnName, columnName)) {
                        defaultExpression = null;
                        tableAltered = true;
                    } else if (Action.ActionType == AlterTableActionType.DropColumn &&
                               CheckColumnNamesMatch(context, ((DropColumnAction) Action).ColumnName, columnName)) {
                        // Check there are no referential links to this column
                        var refs = context.GetTableImportedForeignKeys(TableName);
                        foreach (var reference in refs) {
                            CheckColumnConstraint(columnName, reference.ForeignColumnNames, reference.ForeignTable, reference.ConstraintName);
                        }

                        // Or from it
                        refs = context.GetTableForeignKeys(TableName);
                        foreach (var reference in refs) {
                            CheckColumnConstraint(columnName, reference.ColumnNames, reference.TableName, reference.ConstraintName);
                        }

                        // Or that it's part of a primary key
                        var primaryKey = context.GetTablePrimaryKey(TableName);
                        if (primaryKey != null)
                            CheckColumnConstraint(columnName, primaryKey.ColumnNames, TableName, primaryKey.ConstraintName);

                        // Or that it's part of a unique set
                        var uniques = context.GetTableUniqueKeys(TableName);
                        foreach (var unique in uniques) {
                            CheckColumnConstraint(columnName, unique.ColumnNames, TableName, unique.ConstraintName);
                        }

                        markDropped = true;
                        tableAltered = true;
                    }

                    var newColumn = new ColumnInfo(columnName, columnType);
                    if (defaultExpression != null)
                        newColumn.DefaultExpression = defaultExpression;

                    newColumn.IndexType = column.IndexType;
                    newColumn.IsNotNull = column.IsNotNull;

                    // If not dropped then add to the new table definition.
                    if (!markDropped) {
                        newTableInfo.AddColumn(newColumn);
                    }
                }

                if (Action.ActionType == AlterTableActionType.AddColumn) {
                    var col = ((AddColumnAction)Action).Column;

                    checker.CheckExpression(col.DefaultExpression);
                    var columnName = col.ColumnName;
                    var columnType = col.ColumnType;

                    // If column name starts with [table_name]. then strip it off
                    columnName = checker.StripTableName(TableName.Name, columnName);
                    if (tableInfo.IndexOfColumn(col.ColumnName) != -1)
                        throw new InvalidOperationException("The column '" + col.ColumnName + "' is already in the table '" + tableInfo.TableName + "'.");

                    var newColumn = new ColumnInfo(columnName, columnType) {
                        IsNotNull = col.IsNotNull,
                        DefaultExpression = col.DefaultExpression
                    };

                    newTableInfo.AddColumn(newColumn);
                    tableAltered = true;
                }

                if (Action.ActionType == AlterTableActionType.DropConstraint) {
                    string constraintName = ((DropConstraintAction)Action).ConstraintName;
                    int dropCount = context.DropConstraint(TableName, constraintName);
//.........这里部分代码省略.........
开发者ID:prepare,项目名称:deveeldb,代码行数:101,代码来源:AlterTableStatement.cs


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