internal void InitializeAccessors(
     NavigationPropertyAccessor fromAccessor,
     NavigationPropertyAccessor toAccessor)
 {
     this._fromAccessor = fromAccessor;
     this._toAccessor   = toAccessor;
 }
        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.DeclaringType.FullName,
                    sourceMember.Name,
                    targetMember.Name,
                    sourceAccessor,
                    targetAccessor,
                    sourceMember.RelationshipMultiplicity,
                    relatedEnd);

                break;
            }

            case RelationshipMultiplicity.Many:
            {
                getRelatedEnd = (manager, relatedEnd) =>
                                manager.GetRelatedCollection <TSource, TTarget>(
                    sourceMember.DeclaringType.FullName,
                    sourceMember.Name,
                    targetMember.Name,
                    sourceAccessor,
                    targetAccessor,
                    sourceMember.RelationshipMultiplicity,
                    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);
        }
        // ------------
        // Constructors
        // ------------

        /// <summary>
        /// Creates a navigation object with the given relationship
        /// name, role name for the source and role name for the
        /// destination.
        /// </summary>
        /// <param name="relationshipName">Canonical-space name of the relationship.</param>
        /// <param name="from">Name of the role which is the source of the navigation.</param>
        /// <param name="to">Name of the role which is the destination of the navigation.</param>
        /// <param name="fromAccessor">The navigation property which is the source of the navigation.</param>
        /// <param name="toAccessor">The navigation property which is the destination of the navigation.</param>
        internal RelationshipNavigation(string relationshipName, string from, string to, NavigationPropertyAccessor fromAccessor, NavigationPropertyAccessor toAccessor)
        {
            EntityUtil.CheckStringArgument(relationshipName, "relationshipName");
            EntityUtil.CheckStringArgument(from, "from");
            EntityUtil.CheckStringArgument(to, "to");

            _relationshipName = relationshipName;
            _from             = from;
            _to = to;

            _fromAccessor = fromAccessor;
            _toAccessor   = toAccessor;
        }
 internal RelationshipNavigation(
     AssociationType associationType,
     string from,
     string to,
     NavigationPropertyAccessor fromAccessor,
     NavigationPropertyAccessor toAccessor)
 {
     this._associationType  = associationType;
     this._relationshipName = associationType.FullName;
     this._from             = from;
     this._to           = to;
     this._fromAccessor = fromAccessor;
     this._toAccessor   = toAccessor;
 }
        // ------------
        // Constructors
        // ------------

        // <summary>
        // Creates a navigation object with the given relationship
        // name, role name for the source and role name for the
        // destination.
        // </summary>
        // <param name="relationshipName"> Canonical-space name of the relationship. </param>
        // <param name="from"> Name of the role which is the source of the navigation. </param>
        // <param name="to"> Name of the role which is the destination of the navigation. </param>
        // <param name="fromAccessor"> The navigation property which is the source of the navigation. </param>
        // <param name="toAccessor"> The navigation property which is the destination of the navigation. </param>
        internal RelationshipNavigation(
            string relationshipName, string from, string to, NavigationPropertyAccessor fromAccessor, NavigationPropertyAccessor toAccessor)
        {
            Check.NotEmpty(relationshipName, "relationshipName");
            Check.NotEmpty(@from, "from");
            Check.NotEmpty(to, "to");

            _relationshipName = relationshipName;
            _from             = from;
            _to = to;

            _fromAccessor = fromAccessor;
            _toAccessor   = toAccessor;
        }
 internal RelationshipNavigation(
     string relationshipName,
     string from,
     string to,
     NavigationPropertyAccessor fromAccessor,
     NavigationPropertyAccessor toAccessor)
 {
     Check.NotEmpty(relationshipName, nameof(relationshipName));
     Check.NotEmpty(from, nameof(from));
     Check.NotEmpty(to, nameof(to));
     this._relationshipName = relationshipName;
     this._from             = from;
     this._to           = to;
     this._fromAccessor = fromAccessor;
     this._toAccessor   = toAccessor;
 }
        // <summary>
        // Creates a navigation object with the given relationship
        // name, role name for the source and role name for the
        // destination.
        // </summary>
        // <param name="associationType"> The association type representing the relationship. </param>
        // <param name="from"> Name of the role which is the source of the navigation. </param>
        // <param name="to"> Name of the role which is the destination of the navigation. </param>
        // <param name="fromAccessor"> The navigation property which is the source of the navigation. </param>
        // <param name="toAccessor"> The navigation property which is the destination of the navigation. </param>
        internal RelationshipNavigation(AssociationType associationType, string from, string to,
                                        NavigationPropertyAccessor fromAccessor, NavigationPropertyAccessor toAccessor)
        {
            DebugCheck.NotNull(associationType);
            DebugCheck.NotEmpty(@from);
            DebugCheck.NotEmpty(to);

            _associationType = associationType;

            _relationshipName = associationType.FullName;
            _from             = from;
            _to = to;

            _fromAccessor = fromAccessor;
            _toAccessor   = toAccessor;
        }
Beispiel #8
0
        private static Func <RelationshipManager, RelatedEnd, RelatedEnd> CreateGetRelatedEndMethod(
            AssociationEndMember sourceMember,
            AssociationEndMember targetMember)
        {
            EntityType entityTypeForEnd1 = MetadataHelper.GetEntityTypeForEnd(sourceMember);
            EntityType entityTypeForEnd2 = MetadataHelper.GetEntityTypeForEnd(targetMember);
            NavigationPropertyAccessor propertyAccessor1 = MetadataHelper.GetNavigationPropertyAccessor(entityTypeForEnd2, targetMember, sourceMember);
            NavigationPropertyAccessor propertyAccessor2 = MetadataHelper.GetNavigationPropertyAccessor(entityTypeForEnd1, sourceMember, targetMember);

            return((Func <RelationshipManager, RelatedEnd, RelatedEnd>) typeof(DelegateFactory).GetDeclaredMethod(nameof(CreateGetRelatedEndMethod), typeof(AssociationEndMember), typeof(AssociationEndMember), typeof(NavigationPropertyAccessor), typeof(NavigationPropertyAccessor)).MakeGenericMethod(entityTypeForEnd1.ClrType, entityTypeForEnd2.ClrType).Invoke((object)null, new object[4]
            {
                (object)sourceMember,
                (object)targetMember,
                (object)propertyAccessor1,
                (object)propertyAccessor2
            }));
        }
        private static Func <RelationshipManager, RelatedEnd, RelatedEnd> CreateGetRelatedEndMethod(AssociationEndMember sourceMember, AssociationEndMember targetMember)
        {
            Debug.Assert(sourceMember.DeclaringType == targetMember.DeclaringType, "Source and Target members must be in the same DeclaringType");

            EntityType sourceEntityType = MetadataHelper.GetEntityTypeForEnd(sourceMember);
            EntityType targetEntityType = MetadataHelper.GetEntityTypeForEnd(targetMember);
            NavigationPropertyAccessor sourceAccessor = MetadataHelper.GetNavigationPropertyAccessor(targetEntityType, targetMember, sourceMember);
            NavigationPropertyAccessor targetAccessor = MetadataHelper.GetNavigationPropertyAccessor(sourceEntityType, sourceMember, targetMember);

            MethodInfo genericCreateRelatedEndMethod = typeof(LightweightCodeGenerator).GetMethod("CreateGetRelatedEndMethod", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(AssociationEndMember), typeof(AssociationEndMember), typeof(NavigationPropertyAccessor), typeof(NavigationPropertyAccessor) }, null);

            Debug.Assert(genericCreateRelatedEndMethod != null, "Could not find method LightweightCodeGenerator.CreateGetRelatedEndMethod");

            MethodInfo createRelatedEndMethod = genericCreateRelatedEndMethod.MakeGenericMethod(sourceEntityType.ClrType, targetEntityType.ClrType);
            object     getRelatedEndDelegate  = createRelatedEndMethod.Invoke(null, new object[] { sourceMember, targetMember, sourceAccessor, targetAccessor });

            return((Func <RelationshipManager, RelatedEnd, RelatedEnd>)getRelatedEndDelegate);
        }
Beispiel #10
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)));
            }
        }