none
EF 4.1 Model First Cascade Delete on Many-to-Many RRS feed

  • Question

  • Hello,

    I am working on an EF 4.1 project, and we decided to use the model first approach as we were importing a partially completed schema and updating it for the new software. A problem we are facing is finding a way to set associations with an end of many (or *) to TODELETE as we would like for certain entities to cascade delete all of the entities that related to it.

    I have found a solution for code-first, but being new to EF, I'm not sure how to apply this to a model first approach or if it is even possible with the model.

    Any ideas on how to do this?


    --- David Wesst User Experience Consultant | MVP http://david.wes.st | @Wessty
    Thursday, September 1, 2011 4:54 PM

Answers

All replies

  • Man.... I totally need to do this, too.

    Subscribed...

     

    Keith

    Thursday, September 1, 2011 10:36 PM
  • Hi David and kmycek,

    Welcome!

    Model First is for EF4, I think you can refer @Michael's reply here: 

    http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/814e7fbc-ff04-41fc-8ae0-92bc0238638d/

    -----------------

    the Cascade Delete attribute is only valid on the “1” side of the relationship.  So for the many-to-many relationship, setting the Cascade Delete attribute on either side in CSDL is invalid (we will receive some compiler or validation error in the EDM). 

     

    The workaround would be setting the Cascade Delete attribute on the SSDL since many-to-many relationship is actually built up by two one-to-many relationship

    -----------------

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by David WesstMVP Thursday, September 8, 2011 3:09 PM
    Friday, September 2, 2011 7:57 AM
    Moderator
  • Hi,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 8, 2011 5:48 AM
    Moderator
  • Hi Alan,

    My apologies for taking so long to reply. This did definitely did work for me, although based on the "golden rules" mentioned by @Michael, I am going to look into my needs for delete further.

    Thanks again.


    --- David Wesst User Experience Consultant | MVP http://david.wes.st | @Wessty
    Thursday, September 8, 2011 3:09 PM