本文整理汇总了C#中IQueryContext.CheckConstraints方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryContext.CheckConstraints方法的具体用法?C# IQueryContext.CheckConstraints怎么用?C# IQueryContext.CheckConstraints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQueryContext
的用法示例。
在下文中一共展示了IQueryContext.CheckConstraints方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
//.........这里部分代码省略.........
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);
if (dropCount == 0)
throw new InvalidOperationException("Named constraint to drop on table " + TableName + " was not found: " + constraintName);
} else if (Action.ActionType == AlterTableActionType.DropPrimaryKey) {
if (!context.DropPrimaryKey(TableName))
throw new InvalidOperationException("No primary key to delete on table " + TableName);
}
if (Action.ActionType == AlterTableActionType.AddConstraint) {
var constraint = ((AddConstraintAction)Action).Constraint;
bool foreignConstraint = (constraint.ConstraintType == ConstraintType.ForeignKey);
ObjectName refTname = null;
if (foreignConstraint) {
refTname = context.ResolveTableName(constraint.ForeignTable);
}
var columnNames = checker.StripColumnList(TableName.FullName, constraint.ColumnNames);
columnNames = checker.StripColumnList(constraint.ForeignTable.FullName, columnNames);
var expression = checker.CheckExpression(constraint.CheckExpression);
columnNames = checker.CheckColumns(columnNames);
IEnumerable<string> refCols = null;
if (foreignConstraint && constraint.ForeignColumnNames != null) {
var referencedChecker = ColumnChecker.Default(context, refTname);
refCols = referencedChecker.CheckColumns(constraint.ForeignColumnNames);
}
var newConstraint = new ConstraintInfo(constraint.ConstraintType, constraint.TableName, columnNames.ToArray());
if (foreignConstraint) {
newConstraint.ForeignTable = refTname;
newConstraint.ForeignColumnNames = refCols.ToArray();
}
if (constraint.ConstraintType == ConstraintType.Check)
newConstraint.CheckExpression = expression;
context.AddConstraint(TableName, newConstraint);
}
// Alter the existing table to the new format...
if (tableAltered) {
if (newTableInfo.ColumnCount == 0)
throw new InvalidOperationException("Can not ALTER table to have 0 columns.");
context.AlterTable(newTableInfo);
} else {
// If the table wasn't physically altered, check the constraints.
// Calling this method will also make the transaction check all
// deferred constraints during the next commit.
context.CheckConstraints(TableName);
}
// Return '0' if everything successful.
return FunctionTable.ResultTable(context, 0);
}