I have some problems with deleting object. I am getting the following error:
[Test.Item#ab9a9869-b2c1-4262-8d33-9dd9010abd96][SQL: DELETE FROM InvoerItem WHERE DbId = ? AND Version = ?]
The DELETE statement conflicted with the REFERENCE constraint “FK9100B9F130A0A610”. The conflict occurred in database “”, table “dbo.InvoerItemToInvoerItem”, column ‘Listener_id’.
The situation is like this i have an object that has a collection of references to other objects of the same kind these are called listerners.
The mapping for the object looks like this :
public InvoerItemMap()
{
HasManyToMany(x => x.Listeners)
.ChildKeyColumn("Listener_id")
.Cascade.None()
.Access.CamelCaseField(Prefix.Underscore);
}
What is it that causes the exception when deleting an object that has a listeners connected to it? Do I have to inverse the relation ship of the listeners?
No, inverse doesn’t help.
you need to specify what you want to do with the listeners. There are basically two options:
If you decide to unregister the listeners, then … just implement it.
It would be even better to let the entity manage the listeners:
Edit: if you have references from the listeners to the invoerItems, you need to remove them as well:
By the way: in this case you should make the listeners inverse. Don’t forget to map it to the same foreign key.