Skip to content

InvalidCastException when filtering on nullable value types #260

@marcasburnett

Description

@marcasburnett

I have a type with nullable DateTime properties, which in some cases I need to add to my FilterCondition. When I do that, I get the error below. It looks like this is because NullableValueTypeDdbConverter inherits from DdbConverter but changes the nullability of the type parameter, which for value types means a totally different type.

Unable to cast object of type 'EfficientDynamoDb.Internal.Converters.NullableValueTypeDdbConverter1[System.DateTime]' to type 'EfficientDynamoDb.Converters.DdbConverter1[System.DateTime]'.
at EfficientDynamoDb.FluentCondition.Core.FilterBase1.GetPropertyConverter[TProperty](DdbExpressionVisitor visitor, Boolean useSize) at EfficientDynamoDb.FluentCondition.Operators.Common.FilterLessThan2.WriteAttributeValues(DdbWriter& writer, DynamoDbContextMetadata metadata, Int32& valuesCount, DdbExpressionVisitor visitor)
at EfficientDynamoDb.FluentCondition.Core.FilterOrWrapper.WriteAttributeValues(DdbWriter& writer, DynamoDbContextMetadata metadata, Int32& valuesCount, DdbExpressionVisitor visitor)
at EfficientDynamoDb.FluentCondition.Core.FilterOrWrapper.WriteAttributeValues(DdbWriter& writer, DynamoDbContextMetadata metadata, Int32& valuesCount, DdbExpressionVisitor visitor)
at EfficientDynamoDb.FluentCondition.Core.FilterAndWrapper.WriteAttributeValues(DdbWriter& writer, DynamoDbContextMetadata metadata, Int32& valuesCount, DdbExpressionVisitor visitor)
at EfficientDynamoDb.Internal.Extensions.Utf8JsonWriterExtensions.WriteConditionExpression(DdbWriter& writer, NoAllocStringBuilder& builder, DdbExpressionVisitor visitor, FilterBase condition, DynamoDbContextMetadata metadata)
at EfficientDynamoDb.Internal.Extensions.Utf8JsonWriterExtensions.WriteConditionExpression(DdbWriter& writer, FilterBase condition, DynamoDbContextMetadata metadata)
at EfficientDynamoDb.Internal.Operations.PutItem.PutItemHighLevelHttpContent.WriteDataAsync(DdbWriter ddbWriter)
at EfficientDynamoDb.Internal.Operations.Shared.DynamoDbHttpContent.SerializeToStreamAsync(Stream stream, TransportContext context)
at EfficientDynamoDb.Internal.Operations.Shared.DynamoDbHttpContent.SerializeToStreamAsync(Stream stream, TransportContext context)
at EfficientDynamoDb.Internal.Operations.Shared.DynamoDbHttpContent.CreatePooledContentReadStreamAsync()
at EfficientDynamoDb.Internal.HttpApi.SendAsync(DynamoDbContextConfig config, HttpContent httpContent, CancellationToken cancellationToken)
at EfficientDynamoDb.DynamoDbContext.PutItemAsync[TEntity](BuilderNode node, CancellationToken cancellationToken)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions