private object GetPropertyValue(IEdmTypeReference propertyType, object value, ODataResource root)
        {
            if (value == null)
            {
                return(value);
            }

            switch (propertyType.TypeKind())
            {
            case EdmTypeKind.Complex:
                if (CustomConverters.HasObjectConverter(value.GetType()))
                {
                    return(CustomConverters.Convert(value, value.GetType()));
                }
                return(CreateODataEntry(propertyType.FullName(), value.ToDictionary(), root));

            case EdmTypeKind.Collection:
                var collection = propertyType.AsCollection();
                return(new ODataCollectionValue()
                {
                    TypeName = propertyType.FullName(),
                    Items = ((IEnumerable)value).Cast <object>().Select(x => GetPropertyValue(collection.ElementType(), x, root)),
                });

            case EdmTypeKind.Primitive:
                var mappedTypes = _typeMap.Where(x => x.Value == (propertyType.Definition as IEdmPrimitiveType).PrimitiveKind);
                if (mappedTypes.Any())
                {
                    foreach (var mappedType in mappedTypes)
                    {
                        if (Utils.TryConvert(value, mappedType.Key, out var result))
                        {
                            return(result);
                        }
                    }
                    throw new NotSupportedException($"Conversion is not supported from type {value.GetType()} to OData type {propertyType}");
                }
                return(value);

            case EdmTypeKind.Enum:
                return(new ODataEnumValue(value.ToString()));

            case EdmTypeKind.Untyped:
                return(new ODataUntypedValue {
                    RawValue = value.ToString()
                });

            case EdmTypeKind.None:
                if (CustomConverters.HasObjectConverter(value.GetType()))
                {
                    return(CustomConverters.Convert(value, value.GetType()));
                }
                throw new NotSupportedException($"Conversion is not supported from type {value.GetType()} to OData type {propertyType}");

            default:
                return(value);
            }
        }
        private object GetPropertyValue(IEdmTypeReference propertyType, object value)
        {
            if (value == null)
            {
                return(value);
            }

            switch (propertyType.TypeKind())
            {
            case EdmTypeKind.Complex:
                if (CustomConverters.HasObjectConverter(value.GetType()))
                {
                    return(CustomConverters.Convert(value, value.GetType()));
                }
                var complexTypeProperties = propertyType.AsComplex().StructuralProperties();
                return(new ODataComplexValue
                {
                    TypeName = propertyType.FullName(),
                    Properties = value.ToDictionary()
                                 .Where(val => complexTypeProperties.Any(p => p.Name == val.Key))
                                 .Select(x => new ODataProperty
                    {
                        Name = x.Key,
                        Value = GetPropertyValue(complexTypeProperties, x.Key, x.Value),
                    })
                });

            case EdmTypeKind.Collection:
                var collection = propertyType.AsCollection();
                return(new ODataCollectionValue()
                {
                    TypeName = propertyType.FullName(),
                    Items = ((IEnumerable)value).Cast <object>().Select(x => GetPropertyValue(collection.ElementType(), x)),
                });

            case EdmTypeKind.Primitive:
                var mappedTypes = _typeMap.Where(x => x.Value == (propertyType.Definition as IEdmPrimitiveType).PrimitiveKind);
                if (mappedTypes.Any())
                {
                    foreach (var mappedType in mappedTypes)
                    {
                        object result;
                        if (Utils.TryConvert(value, mappedType.Key, out result))
                        {
                            return(result);
                        }
                    }
                    throw new NotSupportedException(string.Format("Conversion is not supported from type {0} to OData type {1}", value.GetType(), propertyType));
                }
                return(value);

            case EdmTypeKind.Enum:
                return(value.ToString());

            case EdmTypeKind.None:
                if (CustomConverters.HasObjectConverter(value.GetType()))
                {
                    return(CustomConverters.Convert(value, value.GetType()));
                }
                throw new NotSupportedException(string.Format("Conversion is not supported from type {0} to OData type {1}", value.GetType(), propertyType));

            default:
                return(value);
            }
        }