title: How to handle cascading deletes on inherited tables?
body: <p>I've run into a problem with ON DELETE CASCADE when using inherited tables.</p>
  
  <p>I've got the following tables (model first) 
  <img src="https://i.stack.imgur.com/11yEV.png" alt="database model"></p>
  
  <p>Now if I want to delete an entry in Entity1.</p>
  
  <pre><code>using (var ctx = new MyEntities())
  {
     var first = ctx.Entity1Set.First();
     ctx.DeleteObject(first);
     ctx.SaveChanges();
  }
  </code></pre>
  
  <p>Simple... But SaveChanges throws the following exception.</p>
  
  <blockquote>
    <p>The DELETE statement conflicted with the REFERENCE constraint
    FK_EntityA_inherits_BaseEntity". The conflict occurred in database
    "MyDB", table "dbo.BaseEntitySet_EntityA", column 'Id'. The statement
    has been terminated.</p>
  </blockquote>
  
  <p>How do I fix this?</p>
  
  <hr>
  
  <h2>UPDATE</h2>
  
  <p>I noticed a difference between how VS2010 and VS2012 model designer outputs SQL.</p>
  
  <p><strong>VS2010</strong>:</p>
  
  <pre><code>-- Creating foreign key on [Id] in table 'BaseEntitySet_EntityA'
  ALTER TABLE [dbo].[BaseEntitySet_EntityA]
  ADD CONSTRAINT [FK_EntityA_inherits_BaseEntity]
      FOREIGN KEY ([Id])
      REFERENCES [dbo].[BaseEntitySet]
          ([Id])
      ON DELETE NO ACTION ON UPDATE NO ACTION;
  GO
  
  -- Creating foreign key on [Id] in table 'BaseEntitySet_EntityB'
  ALTER TABLE [dbo].[BaseEntitySet_EntityB]
  ADD CONSTRAINT [FK_EntityB_inherits_BaseEntity]
      FOREIGN KEY ([Id])
      REFERENCES [dbo].[BaseEntitySet]
          ([Id])
      ON DELETE NO ACTION ON UPDATE NO ACTION;
  GO
  </code></pre>
  
  <p>Notice <strong>ON DELETE NO ACTION</strong></p>
  
  <p><strong>VS2012</strong></p>
  
  <pre><code>-- Creating foreign key on [Id] in table 'BaseEntitySet_EntityA'
  ALTER TABLE [BaseEntitySet_EntityA]
  ADD CONSTRAINT [FK_EntityA_inherits_BaseEntity]
      FOREIGN KEY ([Id])
      REFERENCES [BaseEntitySet]
          ([Id])
      ON DELETE CASCADE ON UPDATE NO ACTION;
  GO
  
  -- Creating foreign key on [Id] in table 'BaseEntitySet_EntityB'
  ALTER TABLE [BaseEntitySet_EntityB]
  ADD CONSTRAINT [FK_EntityB_inherits_BaseEntity]
      FOREIGN KEY ([Id])
      REFERENCES [BaseEntitySet]
          ([Id])
      ON DELETE CASCADE ON UPDATE NO ACTION;
  GO
  </code></pre>
  
  <p>Notice <strong>ON DELETE CASCADE</strong></p>
  
  <p>That's rather significant...</p>