Exemple #1
0
 private void ConfigureForeignKeyWithCascadingDeletes(CascadeAction onDelete)
 {
     StoreOptions(options =>
     {
         options.Schema.For <Issue>().ForeignKey <User>(x => x.AssigneeId, fkd => fkd.OnDelete = onDelete);
     });
 }
Exemple #2
0
 public ColumnExpression ForeignKeyTo(string referencedTableName, string referencedColumnName,
                                      string fkName          = null, CascadeAction onDelete = CascadeAction.NoAction,
                                      CascadeAction onUpdate = CascadeAction.NoAction)
 {
     return(ForeignKeyTo(DbObjectName.Parse(SqlServerProvider.Instance, referencedTableName), referencedColumnName, fkName, onDelete,
                         onUpdate));
 }
Exemple #3
0
 private void ConfigureForeignKeyWithCascadingDeletes(CascadeAction onDelete)
 {
     StoreOptions(options =>
     {
         options.Schema.For <Issue>().ForeignKey <User>(x => x.AssigneeId, fkd => fkd.OnDelete = onDelete);
     });
     theStore.Tenancy.Default.EnsureStorageExists(typeof(User));
 }
Exemple #4
0
        public void read_on_delete_and_on_update(string definition, CascadeAction onDelete, CascadeAction onUpdate)
        {
            var fk = new ForeignKey("fk_people_state_id")
            {
            };

            fk.Parse(definition);
            fk.OnDelete.ShouldBe(onDelete);
            fk.OnUpdate.ShouldBe(onUpdate);
        }
Exemple #5
0
            public ColumnExpression ForeignKeyTo(DbObjectName referencedIdentifier, string referencedColumnName,
                                                 string fkName          = null, CascadeAction onDelete = CascadeAction.NoAction,
                                                 CascadeAction onUpdate = CascadeAction.NoAction)
            {
                var fk = new ForeignKey(fkName ?? _parent.Identifier.ToIndexName("fkey", Column.Name))
                {
                    LinkedTable = referencedIdentifier,
                    ColumnNames = new[] { Column.Name },
                    LinkedNames = new[] { referencedColumnName },
                    OnDelete    = onDelete,
                    OnUpdate    = onUpdate
                };

                _parent.ForeignKeys.Add(fk);

                return(this);
            }
Exemple #6
0
        public static void WriteCascadeAction(this TextWriter writer, string prefix, CascadeAction action)
        {
            switch (action)
            {
            case CascadeAction.Cascade:
                writer.WriteLine($"{prefix} CASCADE");
                break;

            case CascadeAction.NoAction:
                return;

            case CascadeAction.SetDefault:
                writer.WriteLine($"{prefix} SET DEFAULT");
                break;

            case CascadeAction.SetNull:
                writer.WriteLine($"{prefix} SET NULL");
                break;
            }
        }
Exemple #7
0
 public static string DropStatementFor(string schemaName, CascadeAction option = CascadeAction.Cascade)
 {
     return($"drop schema if exists {schemaName} {option.ToString().ToUpperInvariant()};");
 }
Exemple #8
0
 public ColumnExpression ForeignKeyTo(Table referencedTable, string referencedColumnName,
                                      string fkName          = null, CascadeAction onDelete = CascadeAction.NoAction,
                                      CascadeAction onUpdate = CascadeAction.NoAction)
 {
     return(ForeignKeyTo(referencedTable.Identifier, referencedColumnName, fkName, onDelete, onUpdate));
 }