Implementing identifying relationships with EF4

前端 未结 2 744
执念已碎
执念已碎 2021-01-15 17:17

I\'m currently in a situation where I need to delete entities without having access to the associated ObjectContext. I read about identifying relationships and

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-15 18:11

    No, you are in the right path. What you need to do is in the EDM designer, after creating your 2 entities (Parent and Child), right click on the Parent Entity and select Add => Association... and then specify Multiplicity and Navigation property names, and click Ok. You'll see that VS create an association in between which will result on a relationship between these 2 table later on when you generate a database from your model.
    Do not create a property like ParentID on your Child entity as it will be automatically created by the designer once you create the association.
    Furthermore, you can right click on the association in the EDM designer and Select Properties and Select "Cascade" on "End2 OnDelete" option so that the child will be deleted when the parent is deleted.

提交回复
热议问题