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

SetAsCompulsory() public method

Sets the single relationship as compulsory. If this is set to true then the relationship is treated as compulsory else it uses the algorithm of Checking that all the ForeignKey Props are compulsory. This is primarily used by the Reflective ClassDefLoaders in Habanero.Smooth to load ClassDefinitions based on the BusinessObject.
public SetAsCompulsory ( ) : void
return void
        public void SetAsCompulsory()
        {
            _setAsCompulsory = true;
        }

Usage Example

        /// <summary>
        /// Maps the <see cref="PropertyInfo"/> to a Many to One relationship
        /// </summary>
        /// <returns></returns>
        public IRelationshipDef MapManyToOne()
        {
            if (this.PropertyWrapper.DeclaringType == (Type)null) return null;
            if (!MustBeMapped()) return null;

            var relatedObjectType = this.PropertyWrapper.PropertyType;
            if (this.PropertyWrapper.HasAttribute<AutoMapManyToOneAttribute>())
            {
                var manyToOneAttribute = this.PropertyWrapper.GetAttribute<AutoMapManyToOneAttribute>();
                var specifiedType = manyToOneAttribute.RelatedObjectClassType;
                if (specifiedType != null) relatedObjectType = specifiedType.ToTypeWrapper();
            }
            if (!relatedObjectType.IsBusinessObject)
            {
                throw new InvalidDefinitionException(string.Format(
                    "The specified RelatedObjectClassType '{0}' on '{1}.{2}' must be a Business Object",
                    relatedObjectType, this.PropertyWrapper.DeclaringClassName, this.PropertyWrapper.Name));
            }
            if (!relatedObjectType.IsOfType(this.PropertyWrapper.UnderlyingPropertyType))
            {
                throw new InvalidDefinitionException(string.Format(
                    "The specified RelatedObjectClassType '{0}' on '{1}.{2}' must be assignment compatible with the actual property type '{3}'",
                    relatedObjectType, this.PropertyWrapper.DeclaringClassName,
                    this.PropertyWrapper.Name, this.PropertyWrapper.UnderlyingPropertyType));
            }

            var relDef = new SingleRelationshipDef(this.PropertyWrapper.Name, relatedObjectType.UnderlyingType,
                new RelKeyDef(), true, DeleteParentAction.DoNothing);

            SetRelationshipType(relDef);
            if(this.PropertyWrapper.HasCompulsoryAttribute) relDef.SetAsCompulsory();
            relDef.OwningBOHasForeignKey = true;
            SetReverseRelationshipName(relDef);
            var ownerPropName = GetOwningPropName();
            var relatedPropName = GetRelatedPropName(relatedObjectType);
            IRelPropDef relPropDef = new RelPropDef(ownerPropName, relatedPropName);
            relDef.RelKeyDef.Add(relPropDef);
            return relDef;
        }