Habanero.Smooth.OneToManyAutoMapper.MapOneToMany C# (CSharp) Method

MapOneToMany() public method

Map the relationship including the Relationship props.
public MapOneToMany ( ) : IRelationshipDef
return IRelationshipDef
        public IRelationshipDef MapOneToMany()
        {
            var propertyType = this.PropertyWrapper.PropertyType;
            if(!MustBeMapped()) return null;

            var singleReverseRelPropInfos = this.PropertyWrapper.GetSingleReverseRelPropInfos();
            if (singleReverseRelPropInfos.Count > 1)
            {
                throw new InvalidDefinitionException("The Relationship '" + this.PropertyWrapper.Name
                    + "' could not be automapped since there are multiple Single relationships on class '"
                    + this.PropertyWrapper.RelatedClassType + "' that reference the BusinessObject Class '"
                    + this.PropertyWrapper.DeclaringClassName + "'. Please map using ClassDef.XML or Attributes");
            }
            var relationshipAttribute = this.PropertyWrapper.GetAttribute<AutoMapOneToManyAttribute>();
            MultipleRelationshipDef relDef;
            if (propertyType.IsGenericType)
            {
                var relatedClassType = this.PropertyWrapper.RelatedClassType.UnderlyingType;
                relDef = new MultipleRelationshipDef(this.PropertyWrapper.Name, relatedClassType, new RelKeyDef(), true, "", DeleteParentAction.Prevent);

            }else
            {
                string className = StringUtilities.Singularize(this.PropertyWrapper.Name);
                relDef = new MultipleRelationshipDef(this.PropertyWrapper.Name, this.PropertyWrapper.AssemblyQualifiedName, className
                        , new RelKeyDef(), true, "", DeleteParentAction.Prevent);
            }
            if(relationshipAttribute != null)
            {
                relDef.RelationshipType = relationshipAttribute.RelationshipType;
                DeleteParentAction deleteParentAction = relationshipAttribute.DeleteParentAction;
                relDef.DeleteParentAction = deleteParentAction;
            }
            relDef.ReverseRelationshipName = GetReverseRelationshipName();

            var relPropDef = CreateRelPropDef();
            relDef.RelKeyDef.Add(relPropDef);
            return relDef;
        }
        /// <summary>

Usage Example

        /// <summary>
        /// Map this property to a Relationship definition based on its Defintiion
        /// </summary>
        /// <param name="propertyWrapper"></param>
        /// <returns></returns>
        public static IRelationshipDef MapOneToMany(this PropertyWrapper propertyWrapper)
        {
            if (propertyWrapper == null) return null;
            var autoMapper = new OneToManyAutoMapper(propertyWrapper);

            return autoMapper.MapOneToMany();
        }
All Usage Examples Of Habanero.Smooth.OneToManyAutoMapper::MapOneToMany