Exemple #1
0
        private static Func <RelationshipManager, RelatedEnd, RelatedEnd> CreateGetRelatedEndMethod <TSource, TTarget>(
            AssociationEndMember sourceMember, AssociationEndMember targetMember, NavigationPropertyAccessor sourceAccessor,
            NavigationPropertyAccessor targetAccessor)
            where TSource : class
            where TTarget : class
        {
            Func <RelationshipManager, RelatedEnd, RelatedEnd> getRelatedEnd;

            // Get the appropriate method, either collection or reference depending on the target multiplicity
            switch (targetMember.RelationshipMultiplicity)
            {
            case RelationshipMultiplicity.ZeroOrOne:
            case RelationshipMultiplicity.One:
            {
                getRelatedEnd = (manager, relatedEnd) =>
                                manager.GetRelatedReference <TSource, TTarget>(
                    sourceMember,
                    targetMember,
                    sourceAccessor,
                    targetAccessor,
                    relatedEnd);

                break;
            }

            case RelationshipMultiplicity.Many:
            {
                getRelatedEnd = (manager, relatedEnd) =>
                                manager.GetRelatedCollection <TSource, TTarget>(
                    sourceMember,
                    targetMember,
                    sourceAccessor,
                    targetAccessor,
                    relatedEnd);

                break;
            }

            default:
                var type = typeof(RelationshipMultiplicity);
                throw new ArgumentOutOfRangeException(
                          type.Name,
                          Strings.ADP_InvalidEnumerationValue(
                              type.Name, ((int)targetMember.RelationshipMultiplicity).ToString(CultureInfo.InvariantCulture)));
            }

            return(getRelatedEnd);
        }
Exemple #2
0
        internal static void CheckArgumentMergeOption(MergeOption mergeOption)
        {
            switch (mergeOption)
            {
            case MergeOption.NoTracking:
            case MergeOption.AppendOnly:
            case MergeOption.OverwriteChanges:
            case MergeOption.PreserveChanges:
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          typeof(MergeOption).Name,
                          Strings.ADP_InvalidEnumerationValue(
                              typeof(MergeOption).Name, ((int)mergeOption).ToString(CultureInfo.InvariantCulture)));
            }
        }
Exemple #3
0
        private static Func <RelationshipManager, RelatedEnd, RelatedEnd> CreateGetRelatedEndMethod <TSource, TTarget>(
            AssociationEndMember sourceMember,
            AssociationEndMember targetMember,
            NavigationPropertyAccessor sourceAccessor,
            NavigationPropertyAccessor targetAccessor)
            where TSource : class
            where TTarget : class
        {
            switch (targetMember.RelationshipMultiplicity)
            {
            case RelationshipMultiplicity.ZeroOrOne:
            case RelationshipMultiplicity.One:
                return((Func <RelationshipManager, RelatedEnd, RelatedEnd>)((manager, relatedEnd) => (RelatedEnd)manager.GetRelatedReference <TSource, TTarget>(sourceMember, targetMember, sourceAccessor, targetAccessor, relatedEnd)));

            case RelationshipMultiplicity.Many:
                return((Func <RelationshipManager, RelatedEnd, RelatedEnd>)((manager, relatedEnd) => (RelatedEnd)manager.GetRelatedCollection <TSource, TTarget>(sourceMember, targetMember, sourceAccessor, targetAccessor, relatedEnd)));

            default:
                Type type = typeof(RelationshipMultiplicity);
                throw new ArgumentOutOfRangeException(type.Name, Strings.ADP_InvalidEnumerationValue((object)type.Name, (object)((int)targetMember.RelationshipMultiplicity).ToString((IFormatProvider)CultureInfo.InvariantCulture)));
            }
        }