This is a migrated thread and some comments may be shown as answers.

Managing many-to-many relationship so it automatically deletes one side if possible

4 Answers 45 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Myth
Top achievements
Rank 1
Myth asked on 20 Feb 2013, 03:31 PM
I'm having trouble configuring my many to many relationship.

For example:

Class A = Course
Class B = Student

Is it possible to auto-delete the Course, if the last student in the course is being deleted? But not delete the student if a course is deleted?

Will I need to fix this programatically, or can i do this just by configuring openaccess? I'm using fluent mapping api (IsManaged(), IsDependent().

Kind regards,
Stijn

4 Answers, 1 is accepted

Sort by
0
Myth
Top achievements
Rank 1
answered on 20 Feb 2013, 03:43 PM
Also, using change tracking to programatticaly delete the course doesn't work because the 'manged collection' already removes the association before the 'object deleted event' gets fired (when using a managed collection, which is also neceserry)
0
Myth
Top achievements
Rank 1
answered on 21 Feb 2013, 01:11 PM
Implemented the change tracking 'object deleting' event to make it act the way i want. However sometimes i get an sql exception "Telerik.OpenAccess.RT.sql.SQLException: The DELETE statement conflicted with the REFERENCE constraint xxxxxxxxxx". However i don't understand why. Both sides of the navigation have the property 'IsManaged' set. And sometimes it seems to work just fine.
0
Myth
Top achievements
Rank 1
answered on 21 Feb 2013, 03:30 PM
Found out when it fails:

If i delete a course, which is actually an inherited object from course, it fails.
0
PetarP
Telerik team
answered on 25 Feb 2013, 03:18 PM
Hi Myth,

 Judging by your other ticket (#663257) I am led to believe the problem is most likely connected with the way you have defined your model. 
Whenever you have a base class and you get the exception that there is no certain field defined in the given class the only way to workaround that is to specify the full field name in the format (BaseType.fieldName). This way you will not need to have a TempId in your inheritor. 
Please try that and see if that fixes your problem.

Kind regards,
Petar
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Tags
General Discussions
Asked by
Myth
Top achievements
Rank 1
Answers by
Myth
Top achievements
Rank 1
PetarP
Telerik team
Share this question
or