Example #1
0
        /// <summary>
        /// Combines the property types and returns a reference to the resulting facade.
        /// </summary>
        /// <param name="propertyName">The name of the navigation properties being combined. Used only for error messages.</param>
        /// <param name="clientProperty">The client property.</param>
        /// <param name="serverProperty">The server property.</param>
        /// <param name="modelFacade">The model facade.</param>
        /// <returns>
        /// A type reference to the combined type.
        /// </returns>
        private static IEdmTypeReference CombinePropertyTypes(string propertyName, IEdmNavigationProperty clientProperty, IEdmNavigationProperty serverProperty, EdmModelFacade modelFacade)
        {
            Debug.Assert(clientProperty != null, "clientProperty != null");
            Debug.Assert(serverProperty != null, "serverProperty != null");

            IEdmTypeReference clientPropertyType = clientProperty.Type;
            IEdmTypeReference serverPropertyType = serverProperty.Type;

            // ensure that either both sides are a collection or neither is.
            IEdmCollectionTypeReference clientCollectionType = clientPropertyType as IEdmCollectionTypeReference;
            IEdmCollectionTypeReference serverCollectionType = serverPropertyType as IEdmCollectionTypeReference;
            bool isCollection = clientCollectionType != null;

            if (isCollection != (serverCollectionType != null))
            {
                throw new InvalidOperationException(ErrorStrings.EdmNavigationPropertyFacade_InconsistentMultiplicity(propertyName));
            }

            // For collection properties: extract the element types, combine them, then recreate the collection.
            // For reference properties: get the entity types and combine them.
            IEdmType combinedType;

            if (isCollection)
            {
                // get the client element type and ensure it's an entity type.
                IEdmEntityTypeReference clientElementTypeReference = clientCollectionType.ElementType() as IEdmEntityTypeReference;
                if (clientElementTypeReference == null)
                {
                    throw new InvalidOperationException(ErrorStrings.EdmNavigationPropertyFacade_NonEntityType(propertyName, clientProperty.DeclaringType.FullName()));
                }

                // get the server element type and ensure it's an entity type.
                IEdmEntityTypeReference serverElementTypeReference = serverCollectionType.ElementType() as IEdmEntityTypeReference;
                if (serverElementTypeReference == null)
                {
                    throw new InvalidOperationException(ErrorStrings.EdmNavigationPropertyFacade_NonEntityType(propertyName, serverProperty.DeclaringType.FullName()));
                }

                // combine the element types.
                combinedType = modelFacade.CombineWithServerType(clientElementTypeReference.EntityDefinition(), serverElementTypeReference.EntityDefinition());

                // turn it back into a collection, maintaining nullability of the client's element type.
                combinedType = new EdmCollectionType(combinedType.ToEdmTypeReference(clientElementTypeReference.IsNullable));
            }
            else
            {
                // ensure the server property type is an entity type.
                IEdmEntityTypeReference clientEntityTypeReference = clientPropertyType as IEdmEntityTypeReference;
                if (clientEntityTypeReference == null)
                {
                    throw new InvalidOperationException(ErrorStrings.EdmNavigationPropertyFacade_NonEntityType(propertyName, clientProperty.DeclaringType.FullName()));
                }

                // ensure the server property type is an entity type.
                IEdmEntityTypeReference serverEntityTypeReference = serverPropertyType as IEdmEntityTypeReference;
                if (serverEntityTypeReference == null)
                {
                    throw new InvalidOperationException(ErrorStrings.EdmNavigationPropertyFacade_NonEntityType(propertyName, serverProperty.DeclaringType.FullName()));
                }

                combinedType = modelFacade.CombineWithServerType(clientEntityTypeReference.EntityDefinition(), serverEntityTypeReference.EntityDefinition());
            }

            // return a type reference, maintaining the original nullability from the client property type.
            return(combinedType.ToEdmTypeReference(clientPropertyType.IsNullable));
        }
Example #2
0
 /// <summary>
 /// Creates an exception for a intentionally-unsupported part of the API.
 /// This is used to prevent new code from calling previously-unused API, which could be a breaking change
 /// for user implementations of the interface.
 /// </summary>
 /// <param name="methodName">Name of the unsupported method.</param>
 /// <returns>The exception</returns>
 private static Exception CreateExceptionForUnsupportedPublicMethod(string methodName)
 {
     return(new NotSupportedException(ErrorStrings.EdmModelFacade_UnsupportedMethod("IEdmNavigationProperty", methodName)));
 }