I have an EF4 model over a SQL Server 2008 db. In my model I have a many to many relationship:
Articles * – * Comments
and
Projects * – * Comments
In my Model, I simply created an association and set it up to many to many. In my db, I then get two additional tables ArticleComments and ProjectComments, which only hold the primarykeys to each table.
Problem is that when I delete a comment from an Article in my code (using article.Comments.Remove([some comment entity]) it only deletes the row from ArticleComments, and not the actual Comment it self.
Any solutions to this?
I’ve thought about setting it up as a trigger ondelete in the ProjectComments-table, but I feel this should be possible using only the Entity Framework 4 stuff.
What you did only removes the association between an article and a comment (does not delete data from Comments table but from ArticleComments).
For deleting a Comment you must call the DeleteObject method on the context instance. This will also remove the association between the comment and the article (and also between the comment and the project if I’m right).
You can also put a brea kpoint after the call to SaveChanges and see the query that gets executed against the SQL Server with IntelliTrace (or use SQL profiles as a last resort).
Regards…