I have the follow many-to-many relation:

Class ContactGrup : Contact
{
 [Field(LazyLoad = true)]
 [Association(OnOwnerRemove = OnRemoveAction.Clear, 
          OnTargetRemove =OnRemoveAction.Clear)]
 public EntitySet<Contact> Z_ContactGroupContactList { get;  set; }
}
Class Contact
{
 [Field(LazyLoad = true)]
 [Association(OnOwnerRemove = OnRemoveAction.Clear, 
    OnTargetRemove = OnRemoveAction.Clear, PairTo = "Z_ContactGroupContactList")]
 public EntitySet<ContactGroup> Z_ContactGroupList { get;  set; }
}

DataObjects creates an association table with the follow name: "ContactGroup-Z_ContactGroupContactList-Contact"

Contact contact= Contact.Load(1); 
Contact refContact = (Contact)contact.ContactGroupList[0];
cotact.Remove();
refContact.Remove();
m_Session.DisconnectedState.ApplyChanges();

But during the save the SQL server reports the follow error message:

Die DELETE-Anweisung steht in Konflikt mit der REFERENCE-Einschränkung 'FK_ContactGroup-Z_ContactGroupContactList-Contact_Master'. 
Der Konflikt trat in der 'KLIBNET2_V10'-Datenbank,Tabelle 'dbo.ContactGroup-Z_ContactGroupContactList-Contact', column 'ContactGroup' auf.
Die DELETE-Anweisung steht in Konflikt mit der REFERENCE-Einschränkung 'FK_ContactGroup_Contact'. Der Konflikt trat in der 'KLIBNET2_V10'-Datenbank, Tabelle 'dbo.ContactGroup', column 'Id' auf.

The message is in german: He meens that the contact and refContact can not be deleted because he is referenced in the association table.

Is my implementation of the many-to-many relation right?

Maybe the problem is on the OnTargetRemove or on the OnOwnerRemove?

Regards Marco Leonardi

asked Sep 06 '10 at 11:20

MarcoLeonardi's gravatar image

MarcoLeonardi
10557

edited Sep 08 '10 at 05:51

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

Which line leads to an error? A line with m_Session.DisconnectedState.ApplyChanges?

(Sep 07 '10 at 07:20) Alex Yakunin Alex%20Yakunin's gravatar image

Yes exactly.

(Sep 07 '10 at 07:35) MarcoLeonardi MarcoLeonardi's gravatar image

Could you send us the log produced by DataObjects.Net on this operation?

(Sep 08 '10 at 10:16) Alex Yakunin Alex%20Yakunin's gravatar image

Btw, the code is fully correct.

But I know you intensively use events for BLL, so I'd like to check if it could be a side effect of this.

(Sep 08 '10 at 10:17) Alex Yakunin Alex%20Yakunin's gravatar image
Be the first one to answer this question!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA