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

5 posts, 0 answers
  1. Myth
    Myth avatar
    54 posts
    Member since:
    Jan 2010

    Posted 20 Feb 2013 Link to this post

    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
  2. Myth
    Myth avatar
    54 posts
    Member since:
    Jan 2010

    Posted 20 Feb 2013 Link to this post

    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)
  3. DevCraft banner
  4. Myth
    Myth avatar
    54 posts
    Member since:
    Jan 2010

    Posted 21 Feb 2013 Link to this post

    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.
  5. Myth
    Myth avatar
    54 posts
    Member since:
    Jan 2010

    Posted 21 Feb 2013 Link to this post

    Found out when it fails:

    If i delete a course, which is actually an inherited object from course, it fails.
  6. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 25 Feb 2013 Link to this post

    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.
Back to Top
DevCraft banner