Where to define IsManaged and IsDependent?

Thread is closed for posting
2 posts, 1 answers
  1. Mehdi
    Mehdi avatar
    9 posts
    Member since:
    Jun 2012

    Posted 08 Apr 2013 Link to this post

    I want to know where is the right place to define One-To-Many relations. on the One side or the Many side?
    What about IsManaged and IsDependent methods?
    For example is this ok for managed and cascade delete one-to-many relation?
    OneSide.HasAssociation(o => o.Collections)
         .WithOpposite(c => c.One)
         .HasConstraint((o,c) => o.id == c.OneId)

  2. Answer
    Kaloyan Nikolov
    Kaloyan Nikolov avatar
    118 posts

    Posted 09 Apr 2013 Link to this post

    Hello Mehdi,

    When you create One-to-Many association it doesn't matter from which side  you will define it (from th "OneSide", from the "ManyMany" or both). This is in case you don't need Telerik OpenAccess ORM to automatically add or cascade delete objects.

    IsManaged() method - it is enough to set it for the association created from the "OneSide". If you do that it will work if you add an object in the "Collections" property or add it using the "One" property.
    If you define IsManaged() from the "ManySide" then it will work only when you assign an object to the "One" property but will not work from the "Collections" property.

    IsDependent() method - the side from which you start to define the association does mater. You should define it on the side where you want Telerik OpenAccess ORM to cascade delete the related object for you.

    If you don't know how the association will be used I would suggest you to define it from both sides:

    OneSide.HasAssociation(o => o.Collections)
         .WithOpposite(c => c.One)
         .HasConstraint((o,c) => o.id == c.OneId)
    ManySide.HasAssociation(c => c.One)
         .WithOpposite(o => o.Collections)
         .HasConstraint((c, o) => o.id == c.OneId)

    I hope that will help. Do not hesitate to contact us again if you have other questions.

    Kaloyan Nikolov
    the Telerik team
    Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
Back to Top