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

One-sided association and IsManaged

3 Answers 39 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Petr
Top achievements
Rank 1
Petr asked on 22 Sep 2015, 12:07 AM

Is there a way have managed one-sided association?  Let's take this model for example (adding IsManaged() at the end). I'd like to be able to issue

var vendor = new Vendor { Name = "Vnd" };
vendor.VendorContacts.Add( new VendorContact { ContactType = "Type" });
model.Add(vendor);
model.Save();
 

 Sadly when I try to run this I get null exception and I have to save the contact first

var vendor = new Vendor { Name = "Vnd" };
var contact = new VendorContact { ContactType = "Type" };
 
model.Add(contact);
model.Save();
 
vendor.VendorContacts.Add( contact );
 
model.Add(vendor);
model.Save();

3 Answers, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 24 Sep 2015, 09:06 PM
Hello Petr,

The purpose of setting the IsManaged flag of the association to true is to let Telerik Data Access to synchronize both ends of the association. The first benefit of this is that the Foreign Key column/property will be populated automatically. The second benefit is that the child object will be added in the context because it will be persisted when both ends of the association are synchronized. When one end of the association is missing, there will be no effect of managing the association, because the two ends of the association cannot be synchronized and the second object cannot be persisted. This is why you are receiving the null exception.

I hope that helps.

Regards,
Boris Georgiev
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
Petr
Top achievements
Rank 1
answered on 25 Sep 2015, 08:21 AM

Hey Boris,

 so I can take that as

vendor.VendorContacts.Add( new VendorContact {Name = "Name"} );
  
model.Add(vendor);
model.Save();

cannot be achieved for a one sided associations. Would that be right?

Thanks~

0
Boris Georgiev
Telerik team
answered on 25 Sep 2015, 03:40 PM
Hello Petr,

Yes, that is right. This behavior cannot be achieved for one sided association. You should have two sided association to get the benefits of using the IsManaged behavior.

If any other questions arise, do not hesitate to contact us again.

Regards,
Boris Georgiev
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Development (API, general questions)
Asked by
Petr
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Petr
Top achievements
Rank 1
Share this question
or