locked
Entity Framework Code First: cascade on update RRS feed

  • Question

  • Hallo,

    is there a better possibility to turn 'cascade on update' on for a foreignkey-relationship than doing it per script (e.g. as does WillCascadeOnDelete(true) for 'cascade on delete'), if you use Code First?

    Felix

    Monday, July 21, 2014 8:25 PM

Answers

  • Hello,

    >>is there a better possibility to turn 'cascade on update' on for a foreignkey-relationship than doing it per script (e.g. as does WillCascadeOnDelete(true) for 'cascade on delete'), if you use Code First?

    Unfortunately, it does not supply method like WillCascadeOnDelete() to enable cascade on update. And after you add cascade update for a foreignkey-relationship on these generated tables in database, you cannot update detail tables foreign key value by modifying master table primary key since EF doesn’t let us modify primary key through its context object except the TSQL way using ExecuteStoreCommand method which cannot get benefits of using EF.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, July 22, 2014 7:32 AM

All replies

  • Hello,

    >>is there a better possibility to turn 'cascade on update' on for a foreignkey-relationship than doing it per script (e.g. as does WillCascadeOnDelete(true) for 'cascade on delete'), if you use Code First?

    Unfortunately, it does not supply method like WillCascadeOnDelete() to enable cascade on update. And after you add cascade update for a foreignkey-relationship on these generated tables in database, you cannot update detail tables foreign key value by modifying master table primary key since EF doesn’t let us modify primary key through its context object except the TSQL way using ExecuteStoreCommand method which cannot get benefits of using EF.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, July 22, 2014 7:32 AM
  • Hello,

    thank you for the answer, which prevents me walk into this trap due to the brittleness of primary keys in EF. Will that ever change in future?

    Regards

    Tuesday, July 22, 2014 10:37 AM
  • Hi,

    I do not think this would be changed in further since changing the primary ket value is a bad practice and should be avoid.

    If you really want this function, you could post a wish to:

    http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, July 23, 2014 1:49 AM
  • Hi

    Everybody knows that changing the primary key is not a good idea, but in some application it is a need and it is up to the developer to decide. Otherwise it must be totally removed from SQL Server features.

    Please Think about it.

    Saturday, October 31, 2020 12:03 PM