Note that there are some explanatory texts on larger screens.

plurals
  1. POSelectively Disabling Cascade Delete on Many-to-Many Link Table
    primarykey
    data
    text
    <p>Is it possible to selectively remove the Cascade Delete option on an automatically-generated many-to-many link table in Entity Framework 5 Code First? Here's a simple example which needs it:</p> <pre><code>public class Parent { public int Id { get; set; } public virtual IList&lt;ChildA&gt; As { get; set; } public virtual IList&lt;ChildB&gt; Bs { get; set; } } public class ChildA { public int Id { get; set; } [Required] public virtual Parent Parent { get; set; } public virtual IList&lt;ChildB&gt; ChildBJoins { get; set; } } public class ChildB { public int Id { get; set; } [Required] public virtual Parent Parent { get; set; } public virtual IList&lt;ChildA&gt; ChildAJoins { get; set; } } public class TestContext : DbContext { public DbSet&lt;Parent&gt; Parents { get; set; } public DbSet&lt;ChildA&gt; As { get; set; } public DbSet&lt;ChildB&gt; Bs { get; set; } } </code></pre> <p>This context in its current form will not apply to a database because of the cascade delete option introduced on the link table. If I were to create a manual link table, I could use the Fluent API to configure one side of it to not cascade, but the option isn't available on a many-to-many relationship.</p> <p>I'm aware that I can disable Cascade Deletes on all Many-to-Many joins by removing the <code>ManyToManyCascadeDeleteConvention</code> as per <a href="https://stackoverflow.com/questions/13705441/how-to-disable-cascade-delete-for-link-tables-in-ef-code-first">this question</a>, but that's not what I'm after - I just want to be able to do it for one relationship, or ideally one side of one relationsip.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload