Exemple #1
0
        private void ValidateManyToOneValidity(ValidationContext context)
        {
            ReadOnlyCollection <ManyToOneRelation> manyToOneSources = ManyToOneRelation.GetLinksToSources(this);

            foreach (ManyToOneRelation relationship in manyToOneSources)
            {
                // WARNING: The comparison below does not take case sensitive column naming into account
                if (!String.IsNullOrEmpty(relationship.TargetColumnKey) && !String.IsNullOrEmpty(relationship.SourceColumn) &&
                    !relationship.SourceColumn.ToUpperInvariant().Equals(relationship.TargetColumnKey.ToUpperInvariant())
                    )
                {
                    context.LogError(
                        String.Format(
                            "Class {0} column name does not match with column key {1} on it's many to one relation to class {2}",
                            relationship.Source.Name, relationship.TargetColumnKey, relationship.Target.Name),
                        "AW001ValidateManyToOneValidity2Error", relationship);
                }
            }
        }
Exemple #2
0
        public CodeAttributeDeclaration GetHasAndBelongsToAttributeFromTarget(CodeGenerationContext context)
        {
            var attribute = new CodeAttributeDeclaration("HasAndBelongsToMany");

            attribute.Arguments.Add(AttributeHelper.GetPrimitiveTypeAttributeArgument(Source.Name));
            if (TargetCache != CacheEnum.Undefined)
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Cache", "CacheEnum", TargetCache));
            }
            if (TargetCascade != ManyRelationCascadeEnum.None)
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Cascade",
                                                                                      "ManyRelationCascadeEnum",
                                                                                      TargetCascade));
            }

            if (!string.IsNullOrEmpty(TargetCustomAccess))
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("CustomAccess", TargetCustomAccess));
            }
            else if (EffectiveAutomaticAssociations)
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("CustomAccess", context.Namespace + "." + context.InternalPropertyAccessorName + ", " + context.AssemblyName));
            }
            else if (EffectiveTargetAccess != PropertyAccess.Property)
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Access", "PropertyAccess", EffectiveTargetAccess));
            }

            attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("ColumnRef", EffectiveSourceColumn));
            attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("ColumnKey", EffectiveTargetColumn));
            if (EffectiveTargetRelationType == RelationType.Map)
            {
                // TODO: Index & IndexType
            }
            if (TargetInverse)
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Inverse", TargetInverse));
            }
            if (TargetLazy)
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Lazy", TargetLazy));
            }
            if (!string.IsNullOrEmpty(TargetMapType))
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedTypeAttributeArgument("MapType", TargetMapType));
            }
            if (!string.IsNullOrEmpty(TargetOrderBy))
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("OrderBy", TargetOrderBy));
            }
            if (EffectiveTargetRelationType != RelationType.Guess)
            {
                attribute.Arguments.Add(
                    AttributeHelper.GetNamedEnumAttributeArgument("RelationType", "RelationType", EffectiveTargetRelationType));
            }
            if (EffectiveTargetRelationType == RelationType.Set && !string.IsNullOrEmpty(TargetSort))
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Sort", TargetSort));
            }
            if (!string.IsNullOrEmpty(TargetWhere))
            {
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Where", TargetWhere));
            }
            if (TargetNotFoundBehaviour != NotFoundBehaviour.Default)
            {
                attribute.Arguments.Add(
                    AttributeHelper.GetNamedEnumAttributeArgument("NotFoundBehaviour", "NotFoundBehaviour",
                                                                  TargetNotFoundBehaviour));
            }

            ManyToOneRelation.AddOptionalCollectionType(attribute,
                                                        string.IsNullOrEmpty(TargetIUserCollectionType) ? Target.Model.ManyToManyIUserCollectionType : TargetIUserCollectionType,
                                                        Target.AreRelationsGeneric() ? Source.Name : null);

            PopulateCommonFields(attribute);

            return(attribute);
        }