I'm trying to wrap my head around Entity Framework 4. This is probably an easy question ;)
I have the following entities: Article, Comment and Picture. Articles have a one-to-many association with Comments. Articles have also a many-to-many relationship with Pictures.
My question is what would be the proper approach to deleting an Article that has Comments and Pictures. Mind you there are the following scenarios:
- Article has neither Comments, nor Pictures associated.
- Article has Comments but no Pictures.
- Article has Comments and Pictures that aren't shared with other Articles.
- Article has Comments and Pictures that are shared with other Articles. (Only Pictures can be shared, the comments are exclusive).
I've already noticed that just executing:
_db.DeleteObject(art);
does not work and I have to first delete the Comments and the Pictures in advance. Also if the Picture is shared, I only wanted to delete the association to the particular Article not all the associations.
I'm sure there is easier way to achieve this - is there like a "cascade delete" that would take care of this scenario?
I appreciate your help!