Enable cascade delete for RecAction-OutRes relationship
Added DeleteBehavior.Cascade to the RecAction-OutRes one-to-one relationship in RecDbContext. Now, deleting a RecAction will also delete its related OutRes entity automatically. Previously, the delete behavior was not specified.
This commit is contained in:
@@ -39,6 +39,7 @@ public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(op
|
|||||||
modelBuilder.Entity<RecAction>()
|
modelBuilder.Entity<RecAction>()
|
||||||
.HasOne(act => act.OutRes)
|
.HasOne(act => act.OutRes)
|
||||||
.WithOne(res => res.Action)
|
.WithOne(res => res.Action)
|
||||||
.HasForeignKey<OutRes>(res => res.ActionId);
|
.HasForeignKey<OutRes>(res => res.ActionId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user