示例#1
0
        /// <summary>
        /// Adds a new non-binding collection parameter
        /// </summary>
        public ParameterConfiguration CollectionParameter(Type clrElementType, string name)
        {
            IEdmTypeConfiguration       elementTypeConfiguration = GetOperationTypeConfiguration(clrElementType);
            CollectionTypeConfiguration parameterType            = new CollectionTypeConfiguration(elementTypeConfiguration, typeof(IEnumerable <>).MakeGenericType(clrElementType));

            return(AddParameter(name, parameterType));
        }
示例#2
0
        private static IEdmTypeReference GetEdmTypeReference(Dictionary <Type, IEdmType> availableTypes, IEdmTypeConfiguration configuration, bool nullable)
        {
            Contract.Assert(availableTypes != null);

            if (configuration == null)
            {
                return(null);
            }

            EdmTypeKind kind = configuration.Kind;

            if (kind == EdmTypeKind.Collection)
            {
                CollectionTypeConfiguration collectionType    = (CollectionTypeConfiguration)configuration;
                EdmCollectionType           edmCollectionType =
                    new EdmCollectionType(GetEdmTypeReference(availableTypes, collectionType.ElementType, nullable));
                return(new EdmCollectionTypeReference(edmCollectionType));
            }
            else
            {
                Type configurationClrType = TypeHelper.GetUnderlyingTypeOrSelf(configuration.ClrType);

                if (!TypeHelper.IsEnum(configurationClrType))
                {
                    configurationClrType = configuration.ClrType;
                }

                IEdmType type;

                if (availableTypes.TryGetValue(configurationClrType, out type))
                {
                    if (kind == EdmTypeKind.Complex)
                    {
                        return(new EdmComplexTypeReference((IEdmComplexType)type, nullable));
                    }
                    else if (kind == EdmTypeKind.Entity)
                    {
                        return(new EdmEntityTypeReference((IEdmEntityType)type, nullable));
                    }
                    else if (kind == EdmTypeKind.Enum)
                    {
                        return(new EdmEnumTypeReference((IEdmEnumType)type, nullable));
                    }
                    else
                    {
                        throw Error.InvalidOperation(SRResources.UnsupportedEdmTypeKind, kind.ToString());
                    }
                }
                else if (configuration.Kind == EdmTypeKind.Primitive)
                {
                    PrimitiveTypeConfiguration primitiveTypeConfiguration = (PrimitiveTypeConfiguration)configuration;
                    EdmPrimitiveTypeKind       typeKind = EdmTypeBuilder.GetTypeKind(primitiveTypeConfiguration.ClrType);
                    return(EdmCoreModel.Instance.GetPrimitive(typeKind, nullable));
                }
                else
                {
                    throw Error.InvalidOperation(SRResources.NoMatchingIEdmTypeFound, configuration.FullName);
                }
            }
        }
示例#3
0
        public ParameterConfiguration CollectionParameter <TElementType>(string name)
        {
            Type elementType = typeof(TElementType);
            IEdmTypeConfiguration       elementTypeConfiguration = GetProcedureTypeConfiguration(typeof(TElementType));
            CollectionTypeConfiguration parameterType            = new CollectionTypeConfiguration(elementTypeConfiguration, typeof(IEnumerable <>).MakeGenericType(elementType));

            return(AddParameter(name, parameterType));
        }
示例#4
0
        /// <summary>
        /// Sets the return type to a collection of EntityType instances.
        /// </summary>
        /// <typeparam name="TElementEntityType">The type that is an EntityType</typeparam>
        /// <param name="entitySetPath">The entitySetPath which contains the returned EntityType instances</param>
        internal void ReturnsCollectionViaEntitySetPathImplementation <TElementEntityType>(IEnumerable <string> entitySetPath) where TElementEntityType : class
        {
            Type clrCollectionType            = typeof(IEnumerable <TElementEntityType>);
            IEdmTypeConfiguration elementType = ModelBuilder.GetTypeConfigurationOrNull(typeof(TElementEntityType));

            ReturnType     = new CollectionTypeConfiguration(elementType, clrCollectionType);
            EntitySetPath  = entitySetPath;
            OptionalReturn = true;
        }
示例#5
0
        internal void ReturnsCollectionFromEntitySetImplementation <TElementEntityType>(string entitySetName) where TElementEntityType : class
        {
            Type clrCollectionType = typeof(IEnumerable <TElementEntityType>);

            ModelBuilder.EntitySet <TElementEntityType>(entitySetName);
            NavigationSource = ModelBuilder.EntitySets.Single(s => s.Name == entitySetName);
            IEdmTypeConfiguration elementType = ModelBuilder.GetTypeConfigurationOrNull(typeof(TElementEntityType));

            ReturnType     = new CollectionTypeConfiguration(elementType, clrCollectionType);
            OptionalReturn = true;
        }
示例#6
0
        /// <summary>
        /// Adds a new non-binding collection of entity type parameter.
        /// </summary>
        public ParameterConfiguration CollectionEntityParameter(Type clrElementEntityType, string name)
        {
            IEdmTypeConfiguration elementTypeConfiguration =
                ModelBuilder.StructuralTypes.FirstOrDefault(t => t.ClrType == clrElementEntityType) ??
                ModelBuilder.AddEntityType(clrElementEntityType);

            CollectionTypeConfiguration parameterType = new CollectionTypeConfiguration(elementTypeConfiguration,
                                                                                        typeof(IEnumerable <>).MakeGenericType(clrElementEntityType));

            return(AddParameter(name, parameterType));
        }
示例#7
0
        internal void ReturnsCollectionImplementation <TReturnElementType>()
        {
            // TODO: I don't like this temporary solution that says the CLR type of the collection is IEnumerable<T>.
            // It basically has no meaning. That said the CLR type is meaningful for IEdmTypeConfiguration
            // because I still think it is useful for IEdmPrimitiveTypes too.
            // You can imagine the override of this that takes a delegate using the correct CLR type for the return type.
            Type clrCollectionType = typeof(IEnumerable <TReturnElementType>);
            Type clrElementType    = typeof(TReturnElementType);
            IEdmTypeConfiguration edmElementType = GetProcedureTypeConfiguration(clrElementType);

            ReturnType     = new CollectionTypeConfiguration(edmElementType, clrCollectionType);
            OptionalReturn = EdmLibHelpers.IsNullable(clrElementType);
        }
示例#8
0
        public ActionConfiguration ReturnsCollectionFromEntitySet <TElementEntityType>(
            EntitySetConfiguration <TElementEntityType> entitySetConfiguration) where TElementEntityType : class
        {
            if (entitySetConfiguration == null)
            {
                throw Error.ArgumentNull("entitySetConfiguration");
            }

            Type clrCollectionType = typeof(IEnumerable <TElementEntityType>);

            NavigationSource = entitySetConfiguration.EntitySet;
            IEdmTypeConfiguration elementType = ModelBuilder.GetTypeConfigurationOrNull(typeof(TElementEntityType));

            ReturnType = new CollectionTypeConfiguration(elementType, clrCollectionType);
            return(this);
        }
示例#9
0
        private static void AddOperationLinkBuilder(IEdmModel model, IEdmOperation operation, OperationConfiguration operationConfiguration)
        {
            ActionConfiguration   actionConfiguration = operationConfiguration as ActionConfiguration;
            IEdmAction            action = operation as IEdmAction;
            FunctionConfiguration functionConfiguration = operationConfiguration as FunctionConfiguration;
            IEdmFunction          function = operation as IEdmFunction;

            if (operationConfiguration.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Entity)
            {
                if (actionConfiguration != null && actionConfiguration.GetActionLink() != null && action != null)
                {
                    model.SetOperationLinkBuilder(
                        action,
                        new OperationLinkBuilder(actionConfiguration.GetActionLink(), actionConfiguration.FollowsConventions));
                }
                else if (functionConfiguration != null && functionConfiguration.GetFunctionLink() != null && function != null)
                {
                    model.SetOperationLinkBuilder(
                        function,
                        new OperationLinkBuilder(functionConfiguration.GetFunctionLink(), functionConfiguration.FollowsConventions));
                }
            }
            else if (operationConfiguration.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Collection)
            {
                CollectionTypeConfiguration collectionTypeConfiguration =
                    (CollectionTypeConfiguration)operationConfiguration.BindingParameter.TypeConfiguration;

                if (collectionTypeConfiguration.ElementType.Kind == EdmTypeKind.Entity)
                {
                    if (actionConfiguration != null && actionConfiguration.GetFeedActionLink() != null && action != null)
                    {
                        model.SetOperationLinkBuilder(
                            action,
                            new OperationLinkBuilder(actionConfiguration.GetFeedActionLink(), actionConfiguration.FollowsConventions));
                    }
                    else if (functionConfiguration != null && functionConfiguration.GetFeedFunctionLink() != null && function != null)
                    {
                        model.SetOperationLinkBuilder(
                            function,
                            new OperationLinkBuilder(functionConfiguration.GetFeedFunctionLink(), functionConfiguration.FollowsConventions));
                    }
                }
            }
        }