Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@Eranga is right that this is done by <code>ON DELETE CASCADE</code> setting on relation in the database BUT you are using code first approach and EF creates database for you so the problem here is that your model is not correctly defined because EF didn't create cascading rule for you.</p> <p>Why? Because of this:</p> <pre><code>public class Direction { public int DirectionId { get; set; } public string Abbreviation { get; set; } public virtual Forecast Forecast { get; set; } public virtual List&lt;Transport&gt; Transports { get; set; } } </code></pre> <p><code>Abbreviation</code> is FK property and it is nullable! So EF looks at your model and it sees that you defined <code>Direction</code> entity which can have <code>Abbreviation</code> set to null and because of that it can exists orphaned. Change it to:</p> <pre><code>public class Direction { public int DirectionId { get; set; } [Required] public string Abbreviation { get; set; } public virtual Forecast Forecast { get; set; } public virtual List&lt;Transport&gt; Transports { get; set; } } </code></pre> <p>and removing <code>Forecast</code> will delete all related <code>Direction</code> instances and <code>Transport</code> instances. <code>Stop</code> is different story because it is parent entity to <code>Forecast</code> so it will never be removed with <code>Forecast</code>.</p> <p>Edit:</p> <p>One more point - you don't want to add <code>ON DELETE CASCADE</code> to your relations manually because EF have to know about enabled cascade deletes. EF use this information in case where you have related entities loaded.</p> <p>If you place the rule manually into the database you must use fluent mapping and tell EF about this rule as well. Once you force cascade delete in fluent api you don't need to make it manually in the database - it will be created automatically during database recreation.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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