Delete Object and its related entities

后端 未结 4 1904
情歌与酒
情歌与酒 2020-12-20 02:27

Does anyone know how to delete an object and all of it\'s related entities.

For example I have tables, Products, Category, ProductCategory and productDetails, the pr

相关标签:
4条回答
  • 2020-12-20 02:53

    Also, If you look at your edmx file in visual studio, you can select the "association" and select "End1 OnDelete" property and set to "Cascade".

    0 讨论(0)
  • 2020-12-20 03:02

    Take a look at this question.
    There the case of one-level association is described. In case you set the OnDelete action appropriately there should be no problems to delete all associated child objects.

    0 讨论(0)
  • 2020-12-20 03:10

    Thanks for the reply. I have solved my problem. Using the same cascade in EDMX. For the explanation i am answering my own question. :)

    We have to add <OnDelete Action="Cascade"></OnDelete> in EDMX file at two portions

    1. In SSDL portion
    2. In CSDL portion
    0 讨论(0)
  • 2020-12-20 03:11

    It's worth noting that you need to ensure that objects are loaded for them to be deleted - I turned on Cascade but it didn't help until I had the required objects loaded (interestingly I also didn't need the Cascade turned on at all in my case). I've documented details on the post that helped me the most in tracking down the details Entity Framework delete child object

    0 讨论(0)
提交回复
热议问题