Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework Code First - Defining Relationships/Keys
    text
    copied!<p>I am designing my database using code first and I need a little help I think.</p> <p>I am getting this error:</p> <blockquote> <p>Introducing FOREIGN KEY constraint 'SalesOrder_Invoices' on table 'Invoices' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.<br> Could not create constraint. See previous errors.</p> </blockquote> <p>I am trying to have the following relationships/keys:</p> <pre><code>--&gt; = 1 to Many Relationship </code></pre> <ol> <li>Customer --> CustomerLocation<br></li> <li>CustomerLocation --> SalesOrder<br></li> <li>SalesOrder --> Invoice<br></li> <li>SalesRep --> SalesOrder<br></li> <li>PaymentTerm --> Customer<br></li> <li>PaymentTerm --> SalesOrder<br></li> <li>PaymentTerm --> Invoice<br></li> </ol> <p>I am trying to define them by the standard of:</p> <pre><code>&lt;ClassName&gt;&lt;PrimaryKeyID&gt; </code></pre> <p>Example: <code>Customer</code> has <code>ID</code> property, so in <code>CustomerLocation</code> i define the foreign key like so:</p> <pre><code>Public Property CustomerID AS Integer </code></pre> <p>All I have to do is define the foreign key correct? Do I also have to have navigation properties for each key I define?</p> <p>And, can I not have multiple foreign keys on the same primary key of an object?</p> <p><strong>Updated</strong></p> <p>So to define a relationship, do you use the <code>ClassName.PrimaryKeyProperty</code>? or do you use navigation properties? Or both? Confused!!</p> <p><strong>Update 2</strong></p> <p>So to make a relationship work you have to define both sides... I think.</p> <pre><code>Public Class Customer Public Property ID AS Integer Public Overrideable Property Locations AS ICollection(OF CustomerLocation) End Class Public Class CustomerLocation Public Property ID AS Integer Public Property CustomerID AS Integer End Class </code></pre>
 

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