Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity framework update object and change reference
    primarykey
    data
    text
    <p>I'm trying to make update on CustomerRailcard object which has a reference on Railcard object with end * to 1. The problem is, that I cannot delete Railcard object, I have to only change reference on CustomerRailcard object to another RailcardObject. I'm doing it like this:</p> <p>UPDATE:</p> <pre><code>// Updating properties in existing CustomerRailcard. // This won't update navigation properties (Railcard). context.ObjectStateManager.ChangeObjectState(existingCustomerRailcard, EntityState.Modified); context.ApplyCurrentValues("CustomerRailcardsDbo", newCustomerRailcard); // Now I'm trying to update navigation property of CustomerRailcard to the Railcard // by removing the reference from old Railcard to CustomerRailcard. // Railcard can have references to many CustomerRailcards. var oldRailcard = railcardRepository.FindById(customerDetails.CustomerRailcards.FirstOrDefault(r =&gt; r.Id == railcard.Id).Railcard.Id); var customerRailcardToRemove = oldRailcard.CustomerRailcards.FirstOrDefault(cr =&gt; cr.Id == railcard.Id); // Removing reference to CustomerRailcard from Railcard oldRailcard.CustomerRailcards.Remove(customerRailcardToRemove); // Now I'm getting new Railcard I want to have referenced by CustomerRailcard // and I'm changing its reference tu CustomerRailcard var newRailcard = railcardRepository.FindById(railcard.Railcard.Id); // Adding reference to CustomerRailcard newRailcardDboReference.CustomerRailcards.Add(railcard); </code></pre> <p>After running this I'll get this error</p> <p>A relationship from the 'CR_RL_FK' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'CustomerRailcardDbo' must also in the 'Deleted' state.</p> <p>How else should I perform update on this kind of relationship?</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. 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