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

Where to define IsManaged and IsDependent?

1 Answer 147 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.
Mehdi
Top achievements
Rank 1
Mehdi asked on 08 Apr 2013, 08:46 PM
Hi
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)
     .IsDependent()
     .WithOpposite(c => c.One)
     .HasConstraint((o,c) => o.id == c.OneId)
     .IsManaged();

Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Kaloyan Nikolov
Telerik team
answered on 09 Apr 2013, 03:44 PM
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)
     .IsDependent()
     .IsManaged();
 
ManySide.HasAssociation(c => c.One)
     .WithOpposite(o => o.Collections)
     .HasConstraint((c, o) => o.id == c.OneId)
     .IsDependent()
     .IsManaged();

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

Greetings,
Kaloyan Nikolov
the Telerik team
Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
Tags
General Discussions
Asked by
Mehdi
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Share this question
or