Cascade delete - 1- N relationship

Thread is closed for posting
3 posts, 0 answers
  1. Jayavidya
    Jayavidya avatar
    14 posts
    Member since:
    Oct 2010

    Posted 12 Nov 2010 Link to this post

     I have a User class with a collection of User Group in it. When I delete the User, all the entries in the User Group should be deleted according to cascade delete. Please refer to the steps I followed.
    Step 1 : The usergroup collection has ItemType property.
    public partial class User
       { [Telerik.OpenAccess.FieldAlias("groups")]
           public IList<UserGroup> UserGroups
               get { return groups; }

    Step 2 : The app.config with User class details
    <class name="User">
      <field name="groups">
          <extension key="inverse" value="user" />
          <extension key="managed" value="true" />
      <extension key="db-optimistic-locking" value="changed" />
      <extension key="db-key-generator" value="AUTOINC" />

    Step 3: UserGroup with delete property
    <class name="UserGroup">
          <extension key="db-key-generator" value="AUTOINC" />
          <extension key="delete-orphans" value="true" />

    Step 4: When I fetch the User using orm collection and give delete it does not work.It runs into some loop and doesnt end.
    User  deleteUser = (from c in ObjectScope.Extent<User>()
                                       where c.UserId == deleteUserId
                                   select c).First<User>();

    Please advice me asap.
  2. Ady
    Ady avatar
    589 posts

    Posted 17 Nov 2010 Link to this post

    Hello Jayavidya,

     Does the 'groups' field have the - [Telerik.OpenAccess.Depend()] attribute specified? This attribute sets the 'Cascade delete' functionality on. I did test the similar use case and my user group objects were deleted successfully.

    the Telerik team
    See What's New in Telerik OpenAccess ORM in Q3 2010!
    Monday, November 15, 11 am Eastern Time: Register here>>
    Monday, November 15, 10 pm Eastern Time: Register here>>
  3. Jayavidya
    Jayavidya avatar
    14 posts
    Member since:
    Oct 2010

    Posted 18 Nov 2010 Link to this post

    Yes I did add that code..Also you need to provide dependency tag for UserGroup class in the config file
    <field name="group">
          <extension key="dependent" value="true" />
          <collection element-type="User" />

    It is working for me. Thanks for your support!

Back to Top