0

I have the following entity tree:

ParameterDefinition-->ParameterOperation
ParameterDefinition-->ParameterGroup-->Parameter

Also there is a many to many relationship (mapped to a FK-FK table) between ParameterOperation and Parameter. All associations are declared as Delete cascade (only the many to many is not Delete cascade). The thing is that when I MarkAsDeleted Parameter Object through ParameterOperation (ParameterDefinition.ParameterOperations[0].Parameters[0].MarkAsDeleted) it is deleted from DB and the map table is updated as well (row is deleted), but when I try to delete Parameter From ParameterGroup (ParameterDefinition.ParameterGroups[0].Parameters[0].MarkAsDeleted) it is not deleted at all (no delete query is executed on DB). What might be the problem?

Also how do i delete a many to many relationship? for example I want to keep all Parameters and all ParameterOperations but I want to delete the relationship between Parameters[0] and ParameterOperations[0].

How can I do it?

if I set the NavigationProperty - ParameterDefinition.ParameterOperations[0].Parameters.MarkAsDeleted it actually deleted the Parameter from DB what I don't want

4

1 回答 1

0

Simply removing the Parameter Entity from the ParameterOperation's collection, and then saving your context should be enough to delete the many to many relationship that exists in the junction table.

ParameterDefinition.ParameterOperations[0].Parameters.Remove(ParameterDefinition.ParameterOperations[0].Parameters[0]);
Context.SaveChanges();
于 2012-09-10T12:35:55.870 回答