1

We have 2 classes, Parent and Child

The parent has no reference to the child, the child has the following defined in its fluent mapping:

References(x => x.Parent, "Parent_id").Not.Nullable();

When the parent record is deleted, the following error is generated:

The DELETE statement conflicted with the REFERENCE constraint "FKFF68C21EE06905B9". The conflict occurred in database "DatabaseName", table "dbo.tblChild", column 'Parent_id'.
The statement has been terminated.

What would be the correct mapping to enable the deletion of the parent, given that the parent model has no property collection of type child?

user1838662
  • 503
  • 7
  • 17

1 Answers1

1

You cannot delete parent records, that are referenced by child records because of the foreign key constraint. If you do not want to map the children as a collection reference, you will have to delete the reference to the parent record in all child record before deleting the parent record. You can do so by setting the reference to the parent to null (removing your not null constraint) or by deleting the child record.

All other solutions include an inverse child collection in your parent record with a cascade mapping.

rumpelstiefel
  • 466
  • 3
  • 5