Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RelationshipGroupEnd"/> class.
        /// </summary>
        /// <param name="associationSet">The association set.</param>
        /// <param name="associationSetEnd">The association set end.</param>
        public RelationshipGroupEnd(AssociationSet associationSet, AssociationSetEnd associationSetEnd)
        {
            this.EntitySet    = associationSetEnd.EntitySet;
            this.EntityType   = associationSetEnd.AssociationEnd.EntityType;
            this.Multiplicity = associationSet.GetOtherEnd(associationSetEnd).AssociationEnd.Multiplicity;

            this.associationSetEnds = new List <KeyValuePair <AssociationSet, AssociationSetEnd> >();
            this.associationSetEnds.Add(new KeyValuePair <AssociationSet, AssociationSetEnd>(associationSet, associationSetEnd));
            this.Candidates = new List <RelationshipCandidate>();

            this.CapacitySelector = CapacityRangeSelector.GetDefaultCapacityRangeSelector(this.Multiplicity);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RelationshipGroupEnd"/> class.
        /// </summary>
        /// <param name="associationSetAndEndPairs">The association set and end pairs.</param>
        public RelationshipGroupEnd(IEnumerable <KeyValuePair <AssociationSet, AssociationSetEnd> > associationSetAndEndPairs)
        {
            var entitySets = associationSetAndEndPairs.Select(p => p.Value.EntitySet).Distinct();

            ExceptionUtilities.Assert(entitySets.Count() == 1, "All AssociationSetEnds should have the same EntitySet");

            var entityTypes = associationSetAndEndPairs.Select(p => p.Value.AssociationEnd.EntityType).Distinct();

            ExceptionUtilities.Assert(entityTypes.Count() == 1, "All AssociationSetEnds should have the same EntityType");

            this.EntitySet  = entitySets.Single();
            this.EntityType = entityTypes.Single();

            this.Multiplicity = EndMultiplicity.One;

            this.associationSetEnds = new List <KeyValuePair <AssociationSet, AssociationSetEnd> >();
            this.associationSetEnds.AddRange(associationSetAndEndPairs);
            this.Candidates = new List <RelationshipCandidate>();

            this.CapacitySelector = CapacityRangeSelector.GetDefaultCapacityRangeSelector(this.Multiplicity);
        }
        /// <summary>
        /// Gets the default capacity range selector for the given multiplicity.
        /// </summary>
        /// <param name="multiplicity">The multiplicity.</param>
        /// <returns>Capacity range selector for the given multiplicity.</returns>
        public static Func<CapacityRange> GetDefaultCapacityRangeSelector(EndMultiplicity multiplicity)
        {
            switch (multiplicity)
            {
                case EndMultiplicity.One:
                    return () => CapacityRange.ExactlyOne;

                case EndMultiplicity.ZeroOne:
                    {
                        CapacityRangeSelector selector = new CapacityRangeSelector(interestingCapacitiesForOptionalReference);
                        return () => selector.GetNextCapacity();
                    }

                case EndMultiplicity.Many:
                    {
                        CapacityRangeSelector selector = new CapacityRangeSelector(interestingCapacitiesForCollection);
                        return () => selector.GetNextCapacity();
                    }

                default:
                    throw new TaupoInvalidOperationException("Unhandled multiplicity : " + multiplicity);
            }
        }
        /// <summary>
        /// Gets the default capacity range selector for the given multiplicity.
        /// </summary>
        /// <param name="multiplicity">The multiplicity.</param>
        /// <returns>Capacity range selector for the given multiplicity.</returns>
        public static Func <CapacityRange> GetDefaultCapacityRangeSelector(EndMultiplicity multiplicity)
        {
            switch (multiplicity)
            {
            case EndMultiplicity.One:
                return(() => CapacityRange.ExactlyOne);

            case EndMultiplicity.ZeroOne:
            {
                CapacityRangeSelector selector = new CapacityRangeSelector(interestingCapacitiesForOptionalReference);
                return(() => selector.GetNextCapacity());
            }

            case EndMultiplicity.Many:
            {
                CapacityRangeSelector selector = new CapacityRangeSelector(interestingCapacitiesForCollection);
                return(() => selector.GetNextCapacity());
            }

            default:
                throw new TaupoInvalidOperationException("Unhandled multiplicity : " + multiplicity);
            }
        }