Reputation: 19431
I am using Entity Framework code first (version 6) and GraphDiff in my MVC project.
here is some entities which map some tables in database.
public class CommunicationPlan
{
public int CommunicationPlanID { get; private set; }
[Owned]
public List<CommunicationTopic> Topics { get; private set; }
}
public class CommunicationTopic
{
public int CommunicationTopicID { get; private set; }
[Owned]
public List<ContributingMember> Members { get; private set; }
}
public class ContributingMember
{
public int ContributingMemberID { get; private set; }
// other simple properties
}
When I create CommunicationPlan
which have many CommunicationTopic
s with their ContributingMember
s and save the aggregate root CommunicationPlan
, then the GraphDiff will create all the records and relate them in the database.
(as I want exactly)
Problem
When I am trying to delete one of the CommunicationTopic
from existing CommunicationPlan
then this topic is deleted from the database (as I need), But the ContributingMember
s which related to that CommunicationTopic
does NOT deleted from database , It is just their Foreign key values set to be null, and they reside in the database.
When I configure the Foreign key of the ContributingMember
to make it not accepting null values, then I receive the following exception
The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.
Question How can I configure the Entities to make GraphDiff delete ContributingMember
s records when its parent -CommunicationTopic
- deleted?
Upvotes: 1
Views: 438
Reputation: 870
I think you may have two way to fix this issue
Upvotes: 1