Answered by:
Creating child records in a 1 to 0..1 relationship

Question
-
I have been looking over forums and documentation, but I still can't seem to get it to work.
I have a entity called "Party." It has multiple 1 to 0..1 relationships, such as "Carrier", "Producer", "Brokerage", "Insured", "Beneficiary". The reason why is that a "Party" can be multiple things. I can be a producer, an insured, and a beneficiary all at once. Or I can just be an insured. The Party table grabs general information on a party and each of the 0..1 relationships further define that party.
Anyways...
I want to be able to create a party, and then create any child records associated with it. Maybe just a carrier. Maybe a insured and a beneficiary.
I get the use of a button to create the dependent record. But for some reason, it is just not working.
partialvoidAddCarrier_Execute()
{
this.PartyProperty.Carrier = newCarrier();
this.FindControl("Group1").IsVisible = true;
}
But when I do it, I get a validation error. The party in the carrier is not defined as anything. What am I doing wrong?
Much thanks for your help in advance.
Tuesday, July 29, 2014 9:39 PM
Answers
-
You are trying to create it on the navigation property. Create it first on the data source or on the visual collection then assign to the navigation property.
partialvoidAddCarrier_Execute() { //Create the new Carrier entity on the datasource Carrier newCarrier = this.DataWorkSpace.YourDataSource.Carriers.AddNew(); //Or, create it on the visual collection if it is part of the screen view model Carrier newCarrier = this.Carriers.AddNew(); //Either way will work //Initialize other properties if you want newCarrier.SomeOtherProperty = "Something"; //Assign to the navigation property this.PartyProperty.Carrier = newCarrier; //Do stuff to controls this.FindControl("Group1").IsVisible = true; }
- Edited by Hessc Tuesday, July 29, 2014 10:10 PM
- Proposed as answer by Hessc Tuesday, July 29, 2014 10:10 PM
- Marked as answer by Anthony Genovese Tuesday, July 29, 2014 10:36 PM
Tuesday, July 29, 2014 10:09 PM
All replies
-
You are trying to create it on the navigation property. Create it first on the data source or on the visual collection then assign to the navigation property.
partialvoidAddCarrier_Execute() { //Create the new Carrier entity on the datasource Carrier newCarrier = this.DataWorkSpace.YourDataSource.Carriers.AddNew(); //Or, create it on the visual collection if it is part of the screen view model Carrier newCarrier = this.Carriers.AddNew(); //Either way will work //Initialize other properties if you want newCarrier.SomeOtherProperty = "Something"; //Assign to the navigation property this.PartyProperty.Carrier = newCarrier; //Do stuff to controls this.FindControl("Group1").IsVisible = true; }
- Edited by Hessc Tuesday, July 29, 2014 10:10 PM
- Proposed as answer by Hessc Tuesday, July 29, 2014 10:10 PM
- Marked as answer by Anthony Genovese Tuesday, July 29, 2014 10:36 PM
Tuesday, July 29, 2014 10:09 PM -
Thanks. My brain is not working today. I have literally done the exact thing multiple other times.Tuesday, July 29, 2014 10:37 PM