コード例 #1
0
        /// <summary>
        ///     Retrieves the dependent end of this association, given the following rules in order of priority:
        ///     1. If there is a referential constraint defined on the association, this returns the DependentEnd.
        ///     2. If the association's multiplicity is 1:1 and OnDelete='Cascade' is defined on the first end, then this returns the second end.
        ///     If OnDelete='Cascade' is not defined on the first end, this returns the first end.
        ///     3. In a 1:* or 0..1:* association, this returns the end with the * multiplicity.
        ///     4. In a 0..1:1 association, this returns the end with the 0..1 multiplicity.
        /// </summary>
        /// <param name="association">The association.</param>
        /// <returns>The dependent end.</returns>
        /// <exception cref="InvalidOperationException">if this association is *:*</exception>
        public static AssociationEndMember GetDependentEnd(this AssociationType association)
        {
            Debug.Assert(false == association.IsManyToMany(), Resources.ErrorGetDependentEndOnManyToMany);
            if (association.IsManyToMany())
            {
                throw new InvalidOperationException(Resources.ErrorGetDependentEndOnManyToMany);
            }

            if (association.ReferentialConstraints.Count > 0)
            {
                return(association.ReferentialConstraints.FirstOrDefault().ToRole as AssociationEndMember);
            }
            else
            {
                // Dependency is implied by OnDelete in 1:1 associations
                if (association.GetEnd1().RelationshipMultiplicity == RelationshipMultiplicity.One &&
                    association.GetEnd2().RelationshipMultiplicity == RelationshipMultiplicity.One)
                {
                    return(association.GetEnd1().GetOnDelete() == OperationAction.Cascade ? association.GetEnd2() : association.GetEnd1());
                }

                // Dependency can also be implied by the multiplicity of the association
                if ((association.GetEnd1().RelationshipMultiplicity == RelationshipMultiplicity.Many)
                    ||
                    (association.GetEnd1().RelationshipMultiplicity == RelationshipMultiplicity.ZeroOrOne &&
                     association.GetEnd2().RelationshipMultiplicity == RelationshipMultiplicity.One))
                {
                    return(association.GetEnd1());
                }
                return(association.GetEnd2());
            }
        }
コード例 #2
0
 private static IEnumerable <Tuple <ModificationFunctionMemberPath, EdmProperty> > GetIndependentFkColumns(
     EntityType entityType,
     DbDatabaseMapping databaseMapping)
 {
     foreach (AssociationSetMapping associationSetMapping in databaseMapping.GetAssociationSetMappings())
     {
         AssociationType associationType = associationSetMapping.AssociationSet.ElementType;
         if (!associationType.IsManyToMany())
         {
             AssociationEndMember _;
             AssociationEndMember dependentEnd;
             if (!associationType.TryGuessPrincipalAndDependentEnds(out _, out dependentEnd))
             {
                 dependentEnd = associationType.TargetEnd;
             }
             EntityType dependentEntityType = dependentEnd.GetEntityType();
             if (dependentEntityType == entityType || ModificationFunctionMappingGenerator.GetParents(entityType).Contains <EntityType>(dependentEntityType))
             {
                 EndPropertyMapping endPropertyMapping = associationSetMapping.TargetEndMapping.AssociationEnd != dependentEnd ? associationSetMapping.TargetEndMapping : associationSetMapping.SourceEndMapping;
                 foreach (ScalarPropertyMapping propertyMapping in endPropertyMapping.PropertyMappings)
                 {
                     yield return(Tuple.Create <ModificationFunctionMemberPath, EdmProperty>(new ModificationFunctionMemberPath((IEnumerable <EdmMember>) new EdmMember[2]
                     {
                         (EdmMember)propertyMapping.Property,
                         (EdmMember)dependentEnd
                     }, associationSetMapping.AssociationSet), propertyMapping.Column));
                 }
             }
         }
     }
 }
コード例 #3
0
        public void IsManyToMany_should_be_true_when_source_many_and_target_many()
        {
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);

            associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            associationType.SourceEnd.RelationshipMultiplicity = RelationshipMultiplicity.Many;
            associationType.TargetEnd.RelationshipMultiplicity = RelationshipMultiplicity.Many;

            Assert.True(associationType.IsManyToMany());
        }
コード例 #4
0
        public void IsManyToMany_should_be_true_when_source_many_and_target_many()
        {
            var associationType = new AssociationType();

            associationType.SourceEnd = new AssociationEndMember("S", new EntityType());
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType());
            associationType.SourceEnd.RelationshipMultiplicity = RelationshipMultiplicity.Many;
            associationType.TargetEnd.RelationshipMultiplicity = RelationshipMultiplicity.Many;

            Assert.True(associationType.IsManyToMany());
        }
コード例 #5
0
 public void Generate(AssociationType associationType, DbDatabaseMapping databaseMapping)
 {
     if (associationType.Constraint != null)
     {
         AssociationTypeMappingGenerator.GenerateForeignKeyAssociationType(associationType, databaseMapping);
     }
     else if (associationType.IsManyToMany())
     {
         this.GenerateManyToManyAssociation(associationType, databaseMapping);
     }
     else
     {
         this.GenerateIndependentAssociationType(associationType, databaseMapping);
     }
 }
コード例 #6
0
        public void Generate(AssociationType associationType, DbDatabaseMapping databaseMapping)
        {
            DebugCheck.NotNull(associationType);
            DebugCheck.NotNull(databaseMapping);

            if (associationType.Constraint != null)
            {
                GenerateForeignKeyAssociationType(associationType, databaseMapping);
            }
            else if (associationType.IsManyToMany())
            {
                GenerateManyToManyAssociation(associationType, databaseMapping);
            }
            else
            {
                GenerateIndependentAssociationType(associationType, databaseMapping);
            }
        }