示例#1
0
 public SqlForeignKeyConstraintExpression(string constraintName, IReadOnlyList <string> columnNames, SqlReferencesColumnExpression referencesColumnExpression)
     : base(typeof(void))
 {
     this.ConstraintName             = constraintName;
     this.ColumnNames                = columnNames;
     this.ReferencesColumnExpression = referencesColumnExpression;
 }
 public SqlForeignKeyConstraintExpression(string constraintName, IReadOnlyList<string> columnNames, SqlReferencesColumnExpression referencesColumnExpression)
     : base(typeof(void))
 {
     this.ConstraintName = constraintName;
     this.ColumnNames = columnNames;
     this.ReferencesColumnExpression = referencesColumnExpression;
 }
 protected override Expression VisitReferencesColumn(SqlReferencesColumnExpression expression)
 {
     this.hashCode ^= expression.Deferrability.GetHashCode();
     this.hashCode ^= expression.OnDeleteAction.GetHashCode();
     this.hashCode ^= expression.OnUpdateAction.GetHashCode();
     return(base.VisitReferencesColumn(expression));
 }
		protected override Expression VisitReferencesColumn(SqlReferencesColumnExpression referencesColumnExpression)
		{
			if (referencesColumnExpression.Deferrability != SqlColumnReferenceDeferrability.NotDeferrable)
			{
				return new SqlReferencesColumnExpression(referencesColumnExpression.ReferencedTable, SqlColumnReferenceDeferrability.NotDeferrable, referencesColumnExpression.ReferencedColumnNames, referencesColumnExpression.OnDeleteAction, referencesColumnExpression.OnUpdateAction);
			}

			return base.VisitReferencesColumn(referencesColumnExpression);
		}
 public SqlForeignKeyConstraintExpression UpdateColumnNamesAndReferencedColumnExpression(IEnumerable<string> columnNames, SqlReferencesColumnExpression sqlReferencesColumnExpression)
 {
     return new SqlForeignKeyConstraintExpression(this.ConstraintName, columnNames, sqlReferencesColumnExpression);
 }
 public SqlForeignKeyConstraintExpression(string constraintName, IEnumerable<string> columnNames, SqlReferencesColumnExpression referencesColumnExpression)
     : this(constraintName, columnNames.ToReadOnlyList(), referencesColumnExpression)
 {
 }
 protected override Expression VisitReferencesColumn(SqlReferencesColumnExpression expression)
 {
     this.hashCode ^= expression.Deferrability.GetHashCode();
     this.hashCode ^= expression.OnDeleteAction.GetHashCode();
     this.hashCode ^= expression.OnUpdateAction.GetHashCode();
     return base.VisitReferencesColumn(expression);
 }
        protected override Expression VisitReferencesColumn(SqlReferencesColumnExpression expression)
        {
            SqlReferencesColumnExpression current;
            if (!TryGetCurrent(expression, out current))
            {
                return expression;
            }

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

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

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

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

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

            this.currentObject = current.ReferencedTable;
            this.VisitTable(expression.ReferencedTable);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current.ReferencedColumnNames;
            this.VisitObjectList(expression.ReferencedColumnNames);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current;
            return expression;
        }
示例#9
0
 public SqlForeignKeyConstraintExpression UpdateColumnNamesAndReferencedColumnExpression(IEnumerable <string> columnNames, SqlReferencesColumnExpression sqlReferencesColumnExpression)
 {
     return(new SqlForeignKeyConstraintExpression(this.ConstraintName, columnNames, sqlReferencesColumnExpression));
 }
示例#10
0
 public SqlForeignKeyConstraintExpression(string constraintName, IEnumerable <string> columnNames, SqlReferencesColumnExpression referencesColumnExpression)
     : this(constraintName, columnNames.ToReadOnlyCollection(), referencesColumnExpression)
 {
 }
示例#11
0
        protected override Expression VisitReferencesColumn(SqlReferencesColumnExpression referencesColumnExpression)
        {
            this.Write("REFERENCES ");
            this.Visit(referencesColumnExpression.ReferencedTable);
            this.Write("(");

            this.WriteDeliminatedListOfItems(referencesColumnExpression.ReferencedColumnNames, this.WriteQuotedIdentifier);

            this.Write(")");

            if (referencesColumnExpression.OnDeleteAction != SqlColumnReferenceAction.NoAction)
            {
                this.Write(" ON DELETE ");
                this.Write(referencesColumnExpression.OnDeleteAction);
            }

            if (referencesColumnExpression.OnUpdateAction != SqlColumnReferenceAction.NoAction)
            {
                this.Write(" ON UPDATE ");

                this.Write(referencesColumnExpression.OnUpdateAction);
            }

            if (this.sqlDialect.SupportsFeature(SqlFeature.Deferrability))
            {
                this.WriteDeferrability(referencesColumnExpression.Deferrability);
            }

            return referencesColumnExpression;
        }
示例#12
0
		protected virtual Expression VisitReferencesColumn(SqlReferencesColumnExpression referencesColumnExpression)
		{
			return referencesColumnExpression;
		}
        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);
            }
        }
示例#14
0
 protected virtual Expression VisitReferencesColumn(SqlReferencesColumnExpression referencesColumnExpression)
 {
     return(referencesColumnExpression);
 }