/// <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)); }
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); } } }
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)); }
/// <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; }
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; }
/// <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)); }
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); }
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); }
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)); } } } }