Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework Code First: FOREIGN KEY constraint may cause cycles or multiple cascade paths
    primarykey
    data
    text
    <p>Entity Framework Code First can generate the DB for the following POCOs.</p> <pre><code>public class Item { public int Id { get; set; } public string Name { get; set; } } public class ItemPair { public int Id { get; set; } public virtual Item FirstItem { get; set; } public virtual Item SecondItem { get; set; } } </code></pre> <p>I would like to establish the relationship with First and Second item via ID fields rather than the an entire "Item" class. So:</p> <pre><code>public class ItemPair { public int Id { get; set; } public virtual Item FirstItem { get; set; } public int FirstItem_Id { get; set; } public virtual Item SecondItem { get; set; } public int SecondItem_Id { get; set; } } </code></pre> <p>also works. <strong>Edit</strong>: This didn't actually work. Just generates additional FirstItem_Id1 and SecontItem_Id2 columns.</p> <p>But just changing the foreign key properties to FirstItemId, SecondItemId, (without the underscore) like so:</p> <pre><code>public class ItemPair { public int Id { get; set; } public virtual Item FirstItem { get; set; } public int FirstItemId { get; set; } public virtual Item SecondItem { get; set; } public int SecondItemId { get; set; } } </code></pre> <p>results in the following exception.</p> <pre><code>{"Introducing FOREIGN KEY constraint 'ItemPair_SecondItem' on table 'ItemPair' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.\r\nCould not create constraint. See previous errors."} </code></pre> <p>Why? And what can I do to avoid this exception.</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.
 

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