private void GenerateHasAndBelongsToRelationFromSources(CodeTypeDeclaration classDeclaration, CodeNamespace nameSpace, ManyToManyRelation relationship) { if (String.IsNullOrEmpty(relationship.Table)) throw new ArgumentNullException( String.Format("Class {0} does not have a table name on it's many to many relation to class {1}", relationship.Target.Name, relationship.Source.Name)); if (String.IsNullOrEmpty(relationship.TargetColumn)) throw new ArgumentNullException( String.Format("Class {0} does not have a target column name on it's many to many relation to class {1}", relationship.Target.Name, relationship.Source.Name)); if (String.IsNullOrEmpty(relationship.SourceColumn)) throw new ArgumentNullException( String.Format("Class {0} does not have a source column name on it's many to many relation to class {1}", relationship.Target.Name, relationship.Source.Name)); CodeTypeDeclaration sourceClass = GenerateClass(relationship.Source, nameSpace); string propertyName = String.IsNullOrEmpty(relationship.TargetPropertyName) ? NamingHelper.GetPlural(relationship.Target.Name) : NamingHelper.GetPlural(relationship.TargetPropertyName); string propertyType = String.IsNullOrEmpty(relationship.SourcePropertyType) ? GenericListInterface : relationship.SourcePropertyType; CodeMemberField memberField; if (!relationship.Source.AreRelationsGeneric()) memberField = GetMemberField(propertyName, propertyType, Accessor.Private, relationship.SourceAccess); else memberField = GetGenericMemberField(sourceClass.Name, propertyName, propertyType, Accessor.Private, relationship.SourceAccess); classDeclaration.Members.Add(memberField); CodeMemberProperty memberProperty; if (String.IsNullOrEmpty(relationship.TargetDescription)) memberProperty = GetMemberProperty(memberField, NamingHelper.GetPlural(propertyName), true, true, relationship.Source.DoesImplementINotifyPropertyChanged(), null); else memberProperty = GetMemberProperty(memberField, NamingHelper.GetPlural(propertyName), true, true, relationship.Source.DoesImplementINotifyPropertyChanged(), relationship.TargetDescription); classDeclaration.Members.Add(memberProperty); memberProperty.CustomAttributes.Add(relationship.GetHasAndBelongsToAttributeFromTarget()); }
private void GenerateHasAndBelongsToRelationFromSources(CodeTypeDeclaration classDeclaration, CodeNamespace nameSpace, ManyToManyRelation relationship) { if (relationship.TargetPropertyGenerated) GenerateHasMany( classDeclaration, relationship.Target.Name, relationship.EffectiveTargetPropertyName, relationship.TargetPropertyType, relationship.EffectiveTargetAccess, relationship.TargetDescription, relationship.GetHasAndBelongsToAttributeFromTarget(Context), relationship.Source.AreRelationsGeneric(), relationship.Target.DoesImplementINotifyPropertyChanged(), relationship.Target.DoesImplementINotifyPropertyChanging(), relationship.Source.Name, relationship.EffectiveSourcePropertyName, relationship.EffectiveAutomaticAssociations, true, relationship.GetCollectionIdAttribute(relationship.EffectiveTargetRelationType)); }