protected override Expression VisitColumnDefinition(SqlColumnDefinitionExpression columnDefinitionExpression)
        {
            var autoIncrement = columnDefinitionExpression.ConstraintExpressions
                .OfType<SqlSimpleConstraintExpression>()
                .Any(c => c.Constraint == SqlSimpleConstraint.AutoIncrement);

            IEnumerable<Expression> newConstraints = columnDefinitionExpression.ConstraintExpressions;

            if (this.columnsToMakeNotNull.Contains(columnDefinitionExpression.ColumnName))
            {
                newConstraints = newConstraints
                    .Concat(new SqlSimpleConstraintExpression(SqlSimpleConstraint.NotNull));
            }

            if (autoIncrement)
            {
                newConstraints = newConstraints
                    .Where(c => !(c is SqlSimpleConstraintExpression) || ((SqlSimpleConstraintExpression)c).Constraint != SqlSimpleConstraint.NotNull)
                    .Prepend(new SqlSimpleConstraintExpression(SqlSimpleConstraint.PrimaryKey));
            }

            if (ReferenceEquals(newConstraints, columnDefinitionExpression.ConstraintExpressions))
            {
                return base.VisitColumnDefinition(columnDefinitionExpression);
            }
            else
            {
                return columnDefinitionExpression.UpdateConstraints(newConstraints);
            }
        }
        protected override Expression VisitColumnDefinition(SqlColumnDefinitionExpression columnDefinitionExpression)
        {
            this.currentIsPrimaryKey = columnDefinitionExpression.ConstraintExpressions
                .OfType<SqlSimpleConstraintExpression>()
                .Any(c => c.Constraint == SqlSimpleConstraint.PrimaryKey);

            var isAutoIncrement = columnDefinitionExpression.ConstraintExpressions
                .OfType<SqlSimpleConstraintExpression>()
                .Any(c => c.Constraint == SqlSimpleConstraint.AutoIncrement);

            var retval = (SqlColumnDefinitionExpression)base.VisitColumnDefinition(columnDefinitionExpression);

            if (isAutoIncrement)
            {
                var longTypeSqlName = this.sqlDataTypeProvider.GetSqlDataType(typeof(long)).GetSqlName(null);

                if (((SqlTypeExpression)columnDefinitionExpression.ColumnType).TypeName == longTypeSqlName)
                {
                    retval = new SqlColumnDefinitionExpression(retval.ColumnName, new SqlTypeExpression("BIGSERIAL"), retval.ConstraintExpressions);
                }
                else
                {
                    retval = new SqlColumnDefinitionExpression(retval.ColumnName, new SqlTypeExpression("SERIAL"), retval.ConstraintExpressions);
                }
            }

            return retval;
        }
Ejemplo n.º 3
0
        protected virtual Expression VisitColumnDefinition(SqlColumnDefinitionExpression columnDefinitionExpression)
        {
            var constraints = this.VisitExpressionList(columnDefinitionExpression.ConstraintExpressions);

            if (constraints != columnDefinitionExpression.ConstraintExpressions)
            {
                return(new SqlColumnDefinitionExpression(columnDefinitionExpression.ColumnName, columnDefinitionExpression.ColumnType, constraints));
            }

            return(columnDefinitionExpression);
        }
Ejemplo n.º 4
0
 protected override Expression VisitColumnDefinition(SqlColumnDefinitionExpression expression)
 {
     this.hashCode ^= expression.ColumnName?.GetHashCode() ?? 0;
     return(base.VisitColumnDefinition(expression));
 }
 protected override Expression VisitColumnDefinition(SqlColumnDefinitionExpression expression)
 {
     this.hashCode ^= expression.ColumnName?.GetHashCode() ?? 0;
     return base.VisitColumnDefinition(expression);
 }
        protected override Expression VisitColumnDefinition(SqlColumnDefinitionExpression expression)
        {
            SqlColumnDefinitionExpression current;
            if (!TryGetCurrent(expression, out current))
            {
                return expression;
            }

            if (!(this.result &= object.Equals(current.ColumnName, expression.ColumnName)))
            {
                return expression;
            }

            if (!(this.result &= current.NodeType == expression.NodeType))
            {
                return expression;
            }

            if (!(this.result &= current.Type == expression.Type))
            {
                return expression;
            }

            this.currentObject = current.ColumnType;
            this.Visit(expression.ColumnType);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current.ConstraintExpressions;
            this.VisitExpressionList(expression.ConstraintExpressions);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current;
            return expression;
        }
Ejemplo n.º 7
0
        protected override Expression VisitColumnDefinition(SqlColumnDefinitionExpression columnDefinitionExpression)
        {
            this.WriteQuotedIdentifier(columnDefinitionExpression.ColumnName);
            this.Write(' ');
            this.Visit(columnDefinitionExpression.ColumnType);

            if (columnDefinitionExpression.ConstraintExpressions.Count > 0)
            {
                this.Write(' ');
            }

            this.WriteDeliminatedListOfItems(columnDefinitionExpression.ConstraintExpressions, c => this.Visit(c), " ");

            return columnDefinitionExpression;
        }
Ejemplo n.º 8
0
		protected virtual Expression VisitColumnDefinition(SqlColumnDefinitionExpression columnDefinitionExpression)
		{
			var constraints = this.VisitExpressionList(columnDefinitionExpression.ConstraintExpressions);

			if (constraints != columnDefinitionExpression.ConstraintExpressions)
			{
				return new SqlColumnDefinitionExpression(columnDefinitionExpression.ColumnName, columnDefinitionExpression.ColumnType, constraints);
			}

			return columnDefinitionExpression;
		}
        private IEnumerable<SqlColumnDefinitionExpression> BuildForeignKeyColumnDefinitions(PropertyDescriptor referencingProperty, ColumnInfo[] columnInfos)
        {
            var relatedPropertyTypeDescriptor = this.model.GetTypeDescriptor(referencingProperty.PropertyType);
            var referencedTableName = relatedPropertyTypeDescriptor.PersistedName;

            var valueRequired = (referencingProperty.ValueRequiredAttribute != null && referencingProperty.ValueRequiredAttribute.Required)
                || referencingProperty.IsPrimaryKey;
            var supportsInlineForeignKeys = this.sqlDialect.SupportsFeature(SqlFeature.InlineForeignKeys);

            var foreignObjectConstraintAttribute = referencingProperty.ForeignObjectConstraintAttribute;

            foreach (var foreignKeyColumn in columnInfos)
            {
                var retval = this.BuildColumnDefinition(foreignKeyColumn);

                if (columnInfos.Length == 1 && supportsInlineForeignKeys)
                {
                    var names = new[] { foreignKeyColumn.DefinitionProperty.PersistedName };
                    var newConstraints = new List<Expression>(retval.ConstraintExpressions);

                    var referencesColumnExpression = new SqlReferencesColumnExpression
                    (
                        new SqlTableExpression(referencedTableName),
                        SqlColumnReferenceDeferrability.InitiallyDeferred,
                        names,
                        FixAction((foreignObjectConstraintAttribute != null && ToSqlColumnReferenceAction(foreignObjectConstraintAttribute.OnDeleteAction) != null) ? ToSqlColumnReferenceAction(foreignObjectConstraintAttribute.OnDeleteAction).Value : (valueRequired ? SqlColumnReferenceAction.Restrict : SqlColumnReferenceAction.SetNull)),
                        FixAction((foreignObjectConstraintAttribute != null && ToSqlColumnReferenceAction(foreignObjectConstraintAttribute.OnDeleteAction) != null) ? ToSqlColumnReferenceAction(foreignObjectConstraintAttribute.OnUpdateAction).Value : SqlColumnReferenceAction.NoAction)
                    );

                    newConstraints.Add(referencesColumnExpression);

                    retval = new SqlColumnDefinitionExpression(retval.ColumnName, retval.ColumnType, newConstraints);
                }

                yield return retval;
            }

            if (columnInfos.Length > 1 || !supportsInlineForeignKeys)
            {
                var currentTableColumnNames = columnInfos.Select(c => c.ColumnName);
                var referencedTableColumnNames = columnInfos.Select(c => c.GetTailColumnName());

                var referencesColumnExpression = new SqlReferencesColumnExpression
                (
                    new SqlTableExpression(referencedTableName),
                    SqlColumnReferenceDeferrability.InitiallyDeferred,
                    referencedTableColumnNames,
                    FixAction((foreignObjectConstraintAttribute != null && ToSqlColumnReferenceAction(foreignObjectConstraintAttribute.OnDeleteAction) != null) ? ToSqlColumnReferenceAction(foreignObjectConstraintAttribute.OnDeleteAction).Value : (valueRequired ? SqlColumnReferenceAction.Restrict : SqlColumnReferenceAction.SetNull)),
                    FixAction((foreignObjectConstraintAttribute != null && ToSqlColumnReferenceAction(foreignObjectConstraintAttribute.OnDeleteAction) != null) ? ToSqlColumnReferenceAction(foreignObjectConstraintAttribute.OnUpdateAction).Value : SqlColumnReferenceAction.NoAction)
                );

                var foreignKeyConstraint = new SqlForeignKeyConstraintExpression(null, currentTableColumnNames, referencesColumnExpression);

                currentTableConstraints.Add(foreignKeyConstraint);
            }
        }