Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe that the exception means the following:</p> <p><strong>The property values that define the referential constraints ...</strong> (these are the primary key property (= <code>Id</code>) value of <code>Bid</code> and the foreign key property (= <code>BidId</code>) value of <code>Transaction</code>)</p> <p><strong>... are not consistent ...</strong> (= have different values)</p> <p><strong>... between principal ...</strong> (= <code>Bid</code>)</p> <p><strong>... and dependent ...</strong> (= <code>Transaction</code>)</p> <p><strong>... objects in the relationship.</strong></p> <p>So, it looks like the following: When the MVC model binder creates the <code>TransactionViewModel</code> as parameter for the <code>Edit</code> action, <code>model.Transaction.BidId</code> and <code>model.Transaction.Bid.Id</code> are different, for example:</p> <ul> <li><code>model.Transaction.BidId.HasValue</code> is <code>true</code> but <code>model.Transaction.Bid</code> is <code>null</code></li> <li><code>model.Transaction.BidId.HasValue</code> is <code>false</code> but <code>model.Transaction.Bid</code> is not <code>null</code></li> <li><code>model.Transaction.BidId.Value</code> != <code>model.Transaction.Bid.Id</code></li> </ul> <p>(The first point is probably <em>not</em> a problem. My guess is that you have situation 2.)</p> <p>The same applies to <code>CurrentStage</code> and <code>Evaluation</code>.</p> <p>Possible solutions:</p> <ul> <li>Set those properties to the same values before you call the <code>Update</code> method of your repository (=hack)</li> <li>Bind <code>TransactionViewModel.Transaction.BidId</code> and <code>TransactionViewModel.Transaction.Bid.Id</code> to two hidden form fields with the same value so that the model binder fills both properties.</li> <li>Use also a ViewModel for your inner <code>Transaction</code> property (and for the navigation properties inside of <code>Transaction</code> as well) which is tailored to your view and which you can map appropriately to the entities in your controller action.</li> </ul> <p>One last point to mention is that this line ...</p> <pre><code>context.Entry(entityToUpdate).State = EntityState.Modified; </code></pre> <p>... does not flag the related objects (<code>Transaction.Bid</code>) as modified, so it would not save any changes of <code>Transaction.Bid</code>. You must set the state for the related objects to <code>Modified</code> as well.</p> <p>Side note: If you don't have any additional mapping with Fluent API for EF all your relationships are not one-to-one but one-to-many because you have separate FK properties. One-to-One relationships with EF require shared primary keys.</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.
    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