Ejemplo n.º 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());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Determines if an association is across solely primary keys
        /// </summary>
        /// <param name="association">The association.</param>
        /// <returns>true if the multiplicity of the association is 1:1, 1:0..1, or 0..1:0..1, and false otherwise</returns>
        public static bool IsPKToPK(this AssociationType association)
        {
            if ((association.GetEnd1().RelationshipMultiplicity == RelationshipMultiplicity.One ||
                 association.GetEnd1().RelationshipMultiplicity == RelationshipMultiplicity.ZeroOrOne)
                &&
                (association.GetEnd2().RelationshipMultiplicity == RelationshipMultiplicity.One ||
                 association.GetEnd2().RelationshipMultiplicity == RelationshipMultiplicity.ZeroOrOne))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        private static bool IsAssociatedWithEntityType(this AssociationType association, EntityType entityType)
        {
            var end1 = association.GetEnd1();
            AssociationEndMember end2 = association.GetEnd2();

            return(end1.GetEntityType() == entityType || end2.GetEntityType() == entityType);
        }
Ejemplo n.º 4
0
 /// <summary>
 ///     Given an AssociationEndMember of this Association, this method will return the other end participating
 ///     in the association
 /// </summary>
 /// <param name="association">The Association.</param>
 /// <param name="end">An AssociationEndMember.</param>
 /// <returns>The other end.</returns>
 public static AssociationEndMember GetOtherEnd(this AssociationType association, AssociationEndMember end)
 {
     if (end != null)
     {
         return(end == association.GetEnd1() ? association.GetEnd2() : association.GetEnd1());
     }
     return(null);
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     Determines if an association's multiplicity is *:*
 /// </summary>
 /// <param name="association">The association.</param>
 /// <returns>true if association's multiplicity is *:*, false otherwise</returns>
 public static bool IsManyToMany(this AssociationType association)
 {
     return(association.GetEnd1().RelationshipMultiplicity == RelationshipMultiplicity.Many &&
            association.GetEnd2().RelationshipMultiplicity == RelationshipMultiplicity.Many);
 }