protected override Expression VisitCreateTable(SqlCreateTableExpression createTableExpression) { var autoIncrementColumn = createTableExpression.ColumnDefinitionExpressions.SingleOrDefault(c => c.ConstraintExpressions.OfType<SqlSimpleConstraintExpression>().Any(d => d.Constraint == SqlSimpleConstraint.AutoIncrement)); if (autoIncrementColumn != null) { var primaryKeyConstraint = createTableExpression.TableConstraints.OfType<SqlSimpleConstraintExpression>().SingleOrDefault(c => c.Constraint == SqlSimpleConstraint.PrimaryKey); if (primaryKeyConstraint != null) { if (!primaryKeyConstraint.ColumnNames.Contains(autoIncrementColumn.ColumnName)) { var newPrimaryKeyConstraint = new SqlSimpleConstraintExpression(SqlSimpleConstraint.PrimaryKey, new [] { autoIncrementColumn.ColumnName }); var newUniqueConstraint = new SqlSimpleConstraintExpression(SqlSimpleConstraint.Unique, primaryKeyConstraint.ColumnNames.Concat(autoIncrementColumn.ColumnName).ToArray()); return createTableExpression.UpdateConstraints(new ReadOnlyList<Expression>(createTableExpression.TableConstraints.Where(c => c != primaryKeyConstraint).Concat(newPrimaryKeyConstraint).Concat(newUniqueConstraint))); } } else { var newPrimaryKeyConstraint = new SqlSimpleConstraintExpression(SqlSimpleConstraint.PrimaryKey, new [] { autoIncrementColumn.ColumnName }); return createTableExpression.UpdateConstraints(new ReadOnlyList<Expression>(newPrimaryKeyConstraint)); } } return base.VisitCreateTable(createTableExpression); }
protected override Expression VisitCreateTable(SqlCreateTableExpression createTableExpression) { currentTable = createTableExpression; var retval = base.VisitCreateTable(createTableExpression); currentTable = null; return retval; }
protected override Expression VisitCreateTable(SqlCreateTableExpression createTableExpression) { var count = 0; foreach (var columnDefinition in createTableExpression .ColumnDefinitionExpressions .Where(columnDefinition => columnDefinition .ConstraintExpressions .OfType<SqlSimpleConstraintExpression>() .Any(simpleConstraint => simpleConstraint.Constraint == SqlSimpleConstraint.PrimaryKey))) { count++; if (count >= 2) { break; } } if (count < 2) { return base.VisitCreateTable(createTableExpression); } var newColumnExpressions = new List<SqlColumnDefinitionExpression>(); var newTableConstraintExpressions = new List<Expression>(createTableExpression.TableConstraints); foreach (var columnDefinition in createTableExpression.ColumnDefinitionExpressions) { var newConstraints = columnDefinition.ConstraintExpressions.Where(delegate(Expression constraint) { var simpleConstraint = constraint as SqlSimpleConstraintExpression; if (simpleConstraint == null) { return true; } return simpleConstraint.Constraint != SqlSimpleConstraint.PrimaryKey; }); if (ReferenceEquals(newConstraints, columnDefinition.ConstraintExpressions)) { newColumnExpressions.Add(columnDefinition); } else { newColumnExpressions.Add(new SqlColumnDefinitionExpression(columnDefinition.ColumnName, columnDefinition.ColumnType, newConstraints)); } } return new SqlCreateTableExpression(createTableExpression.Table, false, newColumnExpressions, newTableConstraintExpressions, Enumerable.Empty<SqlTableOption>()); }
protected override Expression VisitCreateTable(SqlCreateTableExpression createTableExpression) { var previousCreateTableExpression = this.currentCreateTableExpression; this.currentCreateTableExpression = createTableExpression; var retval = base.VisitCreateTable(createTableExpression); this.currentCreateTableExpression = previousCreateTableExpression; return retval; }
protected virtual Expression VisitCreateTable(SqlCreateTableExpression createTableExpression) { var newTable = (SqlTableExpression)Visit(createTableExpression.Table); var constraints = VisitExpressionList(createTableExpression.TableConstraints); var columnDefinitions = VisitExpressionList(createTableExpression.ColumnDefinitionExpressions); if (newTable != createTableExpression.Table || createTableExpression.TableConstraints != constraints || createTableExpression.ColumnDefinitionExpressions != columnDefinitions) { return(new SqlCreateTableExpression(newTable, false, columnDefinitions, constraints)); } else { return(createTableExpression); } }
protected override Expression VisitCreateTable(SqlCreateTableExpression expression) { this.hashCode ^= expression.IfNotExist ? 1286760945 : 0; return(base.VisitCreateTable(expression)); }
protected override Expression VisitCreateTable(SqlCreateTableExpression expression) { this.hashCode ^= expression.IfNotExist ? 1286760945 : 0; return base.VisitCreateTable(expression); }
protected override Expression VisitCreateTable(SqlCreateTableExpression expression) { SqlCreateTableExpression current; if (!TryGetCurrent(expression, out current)) { return expression; } if (!(this.result &= current.IfNotExist == expression.IfNotExist)) { return expression; } if (!(this.result &= current.NodeType == expression.NodeType)) { return expression; } if (!(this.result &= current.Type == expression.Type)) { return expression; } this.currentObject = current.Table; this.VisitTable(expression.Table); if (!this.result) { return expression; } this.currentObject = current.TableConstraints; this.VisitExpressionList(expression.TableConstraints); if (!this.result) { return expression; } this.currentObject = current.TableOptions; this.VisitObjectList(expression.TableOptions); if (!this.result) { return expression; } this.currentObject = current.ColumnDefinitionExpressions; this.VisitExpressionList(expression.ColumnDefinitionExpressions); if (!this.result) { return expression; } this.currentObject = current; return expression; }
protected override Expression VisitCreateTable(SqlCreateTableExpression createTableExpression) { var primaryKeyConstraint = createTableExpression .TableConstraints .OfType<SqlSimpleConstraintExpression>() .SingleOrDefault(c => c.Constraint == SqlSimpleConstraint.PrimaryKey); if (primaryKeyConstraint != null) { var autoIncrementColumns = createTableExpression .ColumnDefinitionExpressions .SelectMany(c => c.ConstraintExpressions.OfType<SqlSimpleConstraintExpression>().Select(d => new { Constraint = d, ColumnDefinition = c})) .Where(c => c.Constraint.Constraint == SqlSimpleConstraint.AutoIncrement) .ToList(); if (autoIncrementColumns.Count > 1) { throw new UnsupportedDataAccessModelDefinitionException(); } if (autoIncrementColumns.Count > 0) { var autoIncrementColumn = autoIncrementColumns.Single(); var newTableConstraints = createTableExpression .TableConstraints .Where(c => c != primaryKeyConstraint); if (primaryKeyConstraint.ColumnNames.Length > 1 || autoIncrementColumn.ColumnDefinition.ConstraintExpressions.OfType<SqlSimpleConstraintExpression>().All(c => c.Constraint != SqlSimpleConstraint.PrimaryKey)) { var uniqueConstraint = new SqlSimpleConstraintExpression(SqlSimpleConstraint.Unique, primaryKeyConstraint.ColumnNames); newTableConstraints = newTableConstraints.Concat(uniqueConstraint); } this.primaryKeyNameByTablesWithReducedPrimaryKeyName[createTableExpression.Table.Name] = autoIncrementColumn.ColumnDefinition.ColumnName; this.columnsToMakeNotNull.Clear(); primaryKeyConstraint .ColumnNames .Where(c => c != autoIncrementColumn.ColumnDefinition.ColumnName) .ForEach(c => this.columnsToMakeNotNull.Add(c)); createTableExpression = new SqlCreateTableExpression ( createTableExpression.Table, createTableExpression.IfNotExist, this.VisitExpressionList(createTableExpression.ColumnDefinitionExpressions), newTableConstraints ); this.columnsToMakeNotNull.Clear(); return createTableExpression; } } return base.VisitCreateTable(createTableExpression); }
protected override Expression VisitCreateTable(SqlCreateTableExpression createTableExpression) { this.Write("CREATE TABLE "); this.Visit(createTableExpression.Table); this.WriteLine(); this.Write("("); using (this.AcquireIndentationContext()) { this.WriteDeliminatedListOfItems(createTableExpression.ColumnDefinitionExpressions, c => this.Visit(c), () => this.WriteLine(",")); if (createTableExpression.ColumnDefinitionExpressions.Count > 0 && createTableExpression.TableConstraints.Count > 0) { this.Write(","); } this.WriteLine(); this.WriteDeliminatedListOfItems(createTableExpression.TableConstraints, c => this.Visit(c), () => this.WriteLine(",")); } this.WriteLine(); this.WriteLine(");"); return createTableExpression; }
protected virtual Expression VisitCreateTable(SqlCreateTableExpression createTableExpression) { var newTable = (SqlTableExpression)this.Visit(createTableExpression.Table); var constraints = this.VisitExpressionList(createTableExpression.TableConstraints); var columnDefinitions = this.VisitExpressionList(createTableExpression.ColumnDefinitionExpressions); if (newTable != createTableExpression.Table || createTableExpression.TableConstraints != constraints || createTableExpression.ColumnDefinitionExpressions != columnDefinitions) { return new SqlCreateTableExpression(newTable, false, columnDefinitions, constraints, Enumerable.Empty<SqlTableOption>()); } else { return createTableExpression; } }