/// <summary>
        /// Initializes a new instance of <see cref="EdmFunctionParameterFacade"/> class.
        /// </summary>
        /// <param name="serverFunctionParameter">The function parameter from the server-side model to wrap.</param>
        /// <param name="declaringFunctionFacade">The function import facade which this parameter belongs to.</param>
        /// <param name="modelFacade">The edm model facade this function import belongs to.</param>
        public EdmFunctionParameterFacade(IEdmFunctionParameter serverFunctionParameter, EdmFunctionImportFacade declaringFunctionFacade, EdmModelFacade modelFacade)
        {
            Debug.Assert(serverFunctionParameter != null, "serverFunctionParameter != null");
            Debug.Assert(declaringFunctionFacade != null, "declaringFunctionFacade != null");
            Debug.Assert(modelFacade != null, "modelFacade != null");

            this.serverFunctionParameter = serverFunctionParameter;
            this.declaringFunction = declaringFunctionFacade;
            this.type = modelFacade.GetOrCreateEntityTypeFacadeOrReturnNonEntityServerType(serverFunctionParameter.Type.Definition).ToEdmTypeReference(serverFunctionParameter.Type.IsNullable);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmEntitySetFacade"/> class.
        /// </summary>
        /// <param name="serverEntitySet">The entity set from the server model.</param>
        /// <param name="containerFacade">The entity container facade to which the set belongs.</param>
        /// <param name="modelFacade">The model facade.</param>
        internal EdmEntitySetFacade(IEdmEntitySet serverEntitySet, EdmEntityContainerFacade containerFacade, EdmModelFacade modelFacade)
        {
            Debug.Assert(serverEntitySet != null, "serverEntitySet != null");
            Debug.Assert(containerFacade != null, "container != null");
            Debug.Assert(modelFacade != null, "modelFacade != null");

            this.serverEntitySet = serverEntitySet;
            this.Container       = containerFacade;
            this.modelFacade     = modelFacade;

            this.Name = this.serverEntitySet.Name;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmEntitySetFacade"/> class.
        /// </summary>
        /// <param name="serverEntitySet">The entity set from the server model.</param>
        /// <param name="containerFacade">The entity container facade to which the set belongs.</param>
        /// <param name="modelFacade">The model facade.</param>
        internal EdmEntitySetFacade(IEdmEntitySet serverEntitySet, EdmEntityContainerFacade containerFacade, EdmModelFacade modelFacade)
        {
            Debug.Assert(serverEntitySet != null, "serverEntitySet != null");
            Debug.Assert(containerFacade != null, "container != null");
            Debug.Assert(modelFacade != null, "modelFacade != null");

            this.serverEntitySet = serverEntitySet;
            this.Container = containerFacade;
            this.modelFacade = modelFacade;
            
            this.Name = this.serverEntitySet.Name;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmNavigationPropertyFacade"/> class.
        /// </summary>
        /// <param name="name">The name of the property.</param>
        /// <param name="modelFacade">The model facade.</param>
        /// <param name="declaringTypeFacade">The type facade.</param>
        /// <param name="serverProperty">The server property if one exists.</param>
        /// <param name="clientProperty">The client property.</param>
        internal EdmNavigationPropertyFacade(string name, EdmModelFacade modelFacade, EdmEntityTypeFacade declaringTypeFacade, IEdmNavigationProperty serverProperty, IEdmNavigationProperty clientProperty)
        {
            Debug.Assert(clientProperty != null, "clientProperty != null");
            Debug.Assert(serverProperty != null, "serverProperty != null");
            Debug.Assert(modelFacade != null, "modelFacade != null");
            Debug.Assert(declaringTypeFacade != null, "declaringTypeFacade != null");

            this.Name                = name;
            this.modelFacade         = modelFacade;
            this.declaringTypeFacade = declaringTypeFacade;
            this.serverProperty      = serverProperty;
            this.clientProperty      = clientProperty;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmNavigationPropertyFacade"/> class.
        /// </summary>
        /// <param name="name">The name of the property.</param>
        /// <param name="modelFacade">The model facade.</param>
        /// <param name="declaringTypeFacade">The type facade.</param>
        /// <param name="serverProperty">The server property if one exists.</param>
        /// <param name="clientProperty">The client property.</param>
        internal EdmNavigationPropertyFacade(string name, EdmModelFacade modelFacade, EdmEntityTypeFacade declaringTypeFacade, IEdmNavigationProperty serverProperty, IEdmNavigationProperty clientProperty)
        {
            Debug.Assert(clientProperty != null, "clientProperty != null");
            Debug.Assert(serverProperty != null, "serverProperty != null");
            Debug.Assert(modelFacade != null, "modelFacade != null");
            Debug.Assert(declaringTypeFacade != null, "declaringTypeFacade != null");

            this.Name = name;
            this.modelFacade = modelFacade;
            this.declaringTypeFacade = declaringTypeFacade;
            this.serverProperty = serverProperty;
            this.clientProperty = clientProperty;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of <see cref="EdmFunctionImportFacade"/> class.
        /// </summary>
        /// <param name="serverFunctionImport">The function import from the server-side model which we are wrapping.</param>
        /// <param name="containerFacade">The edm container facade this function import belongs to.</param>
        /// <param name="modelFacade">The edm model facade this function import belongs to.</param>
        public EdmFunctionImportFacade(IEdmFunctionImport serverFunctionImport, EdmEntityContainerFacade containerFacade, EdmModelFacade modelFacade)
        {
            Debug.Assert(serverFunctionImport != null, "serverFunctionImport != null");
            Debug.Assert(containerFacade != null, "containerFacade != null");
            Debug.Assert(modelFacade != null, "modelFacade != null");
            this.serverFunctionImport = serverFunctionImport;
            this.containerFacade = containerFacade;

            IEdmTypeReference serverReturnTypeReference = serverFunctionImport.ReturnType;
            if (serverReturnTypeReference == null)
            {
                this.returnType = null;
            }
            else
            {
                IEdmType serverReturnType = modelFacade.GetOrCreateEntityTypeFacadeOrReturnNonEntityServerType(serverReturnTypeReference.Definition);
                this.returnType = serverReturnType.ToEdmTypeReference(serverReturnTypeReference.IsNullable);
            }

            this.parameters = serverFunctionImport.Parameters.Select(p => new EdmFunctionParameterFacade(p, this, modelFacade)).ToArray();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of <see cref="EdmFunctionImportFacade"/> class.
        /// </summary>
        /// <param name="serverFunctionImport">The function import from the server-side model which we are wrapping.</param>
        /// <param name="containerFacade">The edm container facade this function import belongs to.</param>
        /// <param name="modelFacade">The edm model facade this function import belongs to.</param>
        public EdmFunctionImportFacade(IEdmFunctionImport serverFunctionImport, EdmEntityContainerFacade containerFacade, EdmModelFacade modelFacade)
        {
            Debug.Assert(serverFunctionImport != null, "serverFunctionImport != null");
            Debug.Assert(containerFacade != null, "containerFacade != null");
            Debug.Assert(modelFacade != null, "modelFacade != null");
            this.serverFunctionImport = serverFunctionImport;
            this.containerFacade      = containerFacade;

            IEdmTypeReference serverReturnTypeReference = serverFunctionImport.ReturnType;

            if (serverReturnTypeReference == null)
            {
                this.returnType = null;
            }
            else
            {
                IEdmType serverReturnType = modelFacade.GetOrCreateEntityTypeFacadeOrReturnNonEntityServerType(serverReturnTypeReference.Definition);
                this.returnType = serverReturnType.ToEdmTypeReference(serverReturnTypeReference.IsNullable);
            }

            this.parameters = serverFunctionImport.Parameters.Select(p => new EdmFunctionParameterFacade(p, this, modelFacade)).ToArray();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of <see cref="EdmFunctionParameterFacade"/> class.
        /// </summary>
        /// <param name="serverFunctionParameter">The function parameter from the server-side model to wrap.</param>
        /// <param name="declaringFunctionFacade">The function import facade which this parameter belongs to.</param>
        /// <param name="modelFacade">The edm model facade this function import belongs to.</param>
        public EdmFunctionParameterFacade(IEdmFunctionParameter serverFunctionParameter, EdmFunctionImportFacade declaringFunctionFacade, EdmModelFacade modelFacade)
        {
            Debug.Assert(serverFunctionParameter != null, "serverFunctionParameter != null");
            Debug.Assert(declaringFunctionFacade != null, "declaringFunctionFacade != null");
            Debug.Assert(modelFacade != null, "modelFacade != null");

            this.serverFunctionParameter = serverFunctionParameter;
            this.declaringFunction       = declaringFunctionFacade;
            this.type = modelFacade.GetOrCreateEntityTypeFacadeOrReturnNonEntityServerType(serverFunctionParameter.Type.Definition).ToEdmTypeReference(serverFunctionParameter.Type.IsNullable);
        }
Exemplo n.º 9
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));
        }
        /// <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);
        }