Help on updatine detail in master detail relationship

Thread is closed for posting
3 posts, 0 answers
  1. kieron
    kieron avatar
    9 posts
    Member since:
    Dec 2010

    Posted 10 Oct 2011 Link to this post

    I am having some issues finding documentation on adding a new child in a 1to many relationship.
    I have a class organiser which has many contacts. use winforms i have done the below
    PEHorganisermaster newOrganiser = new PEHorganisermaster();
                            newOrganiser.Name = NameTextEdit.EditValue.ToString();
                            newOrganiser.Address1 = Address1TextEdit.EditValue.ToString();
                            newOrganiser.Address2 = Address2TextEdit.EditValue.ToString();
                            newOrganiser.Suburb = SuburbTextEdit.EditValue.ToString();
                            newOrganiser.State = StateTextEdit.EditValue.ToString();
                            newOrganiser.Postcode = Convert.ToInt32(PostcodeTextEdit.EditValue.ToString());
                            newOrganiser.Country = countrytextedit.editvalue.tostring();
                            newOrganiser.Active = 1;

    Now i wish to start adding contacts to this organiser which are in a seperate table but i am unsure on how to do it so that the new contact is related to this organiser?

    I have tried below
    PEHcontact newcontact = new PEHcontact();
                newcontact.Name = gridView1.GetRowCellValue(e.RowHandle, colName).ToString();
                newcontact.Active = 1;
                newcontact.Mobile = Convert.ToInt32(gridView1.GetRowCellValue(e.RowHandle, colMobile).ToString());

    And it does indeed add the contact to teh contact table the the Organiser_id field is blank which is the foreign key. i would have that that the ORM would auto add the ID from the neworganiser instance.
  2. Ivailo
    Ivailo avatar
    318 posts

    Posted 13 Oct 2011 Link to this post

    Hello Kieron,

    There is a property of the Association between the PEHorganisermaster and PEHcontract Domain Classes called IsManaged that can help you achieve what you what. When this property is set to True, the relationship between the navigation property newOrganiser.PEHcontacts and the actual contract objects is automatically maintained, meaning that when you add a new contract the Organiser_id property will be populated.

    By default, the IsManaged property is set to False for all your associations for performance reasons, so you have to set it to True when you need this linkage automated for you.

    Do not hesitate to let us know if you need any further clarifications on this.

    the Telerik team

    Check out the latest stable build of Telerik OpenAccess ORM. Download it and benefit from our new Project Templates.

  3. kieron
    kieron avatar
    9 posts
    Member since:
    Dec 2010

    Posted 17 Oct 2011 Link to this post

    Thanks by enabling that it worked like a treat
Back to Top