예제 #1
0
        private void GenerateHasAndBelongsToRelationFromTargets(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.Source.Name, relationship.Target.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.Source.Name, relationship.Target.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.Source.Name, relationship.Target.Name));

            CodeTypeDeclaration targetClass = GenerateClass(relationship.Target, nameSpace);

            string propertyName = String.IsNullOrEmpty(relationship.SourcePropertyName)
                                      ? NamingHelper.GetPlural(relationship.Source.Name)
                                      : NamingHelper.GetPlural(relationship.SourcePropertyName);

            string propertyType = String.IsNullOrEmpty(relationship.TargetPropertyType)
                                      ? GenericListInterface
                                      : relationship.TargetPropertyType;

            CodeMemberField memberField;
            if (!relationship.Source.AreRelationsGeneric())
                memberField = GetMemberField(propertyName, propertyType, Accessor.Private, relationship.TargetAccess);
            else
                memberField = GetGenericMemberField(targetClass.Name, propertyName, propertyType, Accessor.Private, relationship.TargetAccess);

            classDeclaration.Members.Add(memberField);

            CodeMemberProperty memberProperty;
            if (String.IsNullOrEmpty(relationship.SourceDescription))
                memberProperty = GetMemberProperty(memberField, NamingHelper.GetPlural(propertyName), true, true, relationship.Target.DoesImplementINotifyPropertyChanged(), null);
            else
                memberProperty =
                    GetMemberProperty(memberField, NamingHelper.GetPlural(propertyName), true, true, relationship.Target.DoesImplementINotifyPropertyChanged(),
                                      relationship.SourceDescription);
            classDeclaration.Members.Add(memberProperty);

            memberProperty.CustomAttributes.Add(relationship.GetHasAndBelongsToAttributeFromSource());
        }
예제 #2
0
 private void GenerateHasAndBelongsToRelationFromTargets(CodeTypeDeclaration classDeclaration, CodeNamespace nameSpace,
                                        ManyToManyRelation relationship)
 {
     if (relationship.SourcePropertyGenerated)
         GenerateHasMany(
             classDeclaration,
             relationship.Source.Name,
             relationship.EffectiveSourcePropertyName,
             relationship.SourcePropertyType,
             relationship.EffectiveSourceAccess,
             relationship.SourceDescription,
             relationship.GetHasAndBelongsToAttributeFromSource(Context),
             relationship.Target.AreRelationsGeneric(),
             relationship.Source.DoesImplementINotifyPropertyChanged(),
             relationship.Source.DoesImplementINotifyPropertyChanging(),
             relationship.Target.Name,
             relationship.EffectiveTargetPropertyName,
             relationship.EffectiveAutomaticAssociations,
             true,
             relationship.GetCollectionIdAttribute(relationship.EffectiveSourceRelationType));
 }