Habanero.BO.ClassDefinition.SingleRelationshipDef.CreateRelationship C# (CSharp) Method

CreateRelationship() public method

Overrides abstract method of RelationshipDef to create a new relationship
public CreateRelationship ( IBusinessObject owningBo, IBOPropCol lBOPropCol ) : IRelationship
owningBo IBusinessObject The business object that will manage /// this relationship
lBOPropCol IBOPropCol The collection of properties
return IRelationship
        public override IRelationship CreateRelationship(IBusinessObject owningBo, IBOPropCol lBOPropCol)
        {
            Type relationshipBOType = typeof (SingleRelationship<>).MakeGenericType(this.RelatedObjectClassType);
            return (ISingleRelationship) Activator.CreateInstance(relationshipBOType, owningBo, this, lBOPropCol);
        }

Usage Example

 public void TestGetRelatedObject()
 {
     RelationshipDef mRelationshipDef;
     RelKeyDef mRelKeyDef;
     MockBO _mMockBO= GetMockBO(out mRelationshipDef, out mRelKeyDef);
     RelationshipDef lRelationshipDef = new SingleRelationshipDef("Relation1", typeof (MockBO), mRelKeyDef, true,
                                                                  DeleteParentAction.Prevent);
     ISingleRelationship rel =
         (ISingleRelationship) lRelationshipDef.CreateRelationship(_mMockBO, _mMockBO.PropCol);
     Assert.AreEqual(lRelationshipDef.RelationshipName, rel.RelationshipName);
     Assert.IsTrue(_mMockBO.GetPropertyValue("MockBOProp1") == null);
     Assert.IsFalse(rel.HasRelatedObject(), "Should be false since props are not defaulted in Mock bo");
     //Set a related object
     _mMockBO.SetPropertyValue("MockBOProp1", _mMockBO.GetPropertyValue("MockBOID"));
     //Save the object, so that the relationship can retrieve the object from the database
     _mMockBO.Save();
     Assert.IsTrue(rel.HasRelatedObject(), "Should have a related object since the relating props have values");
     MockBO ltempBO = (MockBO) rel.GetRelatedObject();
     Assert.IsNotNull(ltempBO, "The related object should exist");
     //Clear the related object
     _mMockBO.SetPropertyValue("MockBOProp1", null);
     Assert.IsFalse(rel.HasRelatedObject(),
                    "Should not have a related object since the relating props have been set to null");
     ltempBO = (MockBO) rel.GetRelatedObject();
     Assert.IsNull(ltempBO, "The related object should now be null");
     //Set a related object again
     _mMockBO.SetPropertyValue("MockBOProp1", _mMockBO.GetPropertyValue("MockBOID"));
     Assert.IsTrue(rel.HasRelatedObject(),
                   "Should have a related object since the relating props have values again");
     ltempBO = (MockBO) rel.GetRelatedObject();
     Assert.IsNotNull(ltempBO, "The related object should exist again");
     _mMockBO.MarkForDelete();
     _mMockBO.Save();
 }
All Usage Examples Of Habanero.BO.ClassDefinition.SingleRelationshipDef::CreateRelationship