linq2dynamodb
linq2dynamodb copied to clipboard
Object property cannot have >1 DynamoDBPropertyAttribute
If a property is part of the primary key and also an index, there's an exception thrown when trying to determine the property converter.
Example:
[DynamoDBHashKey("ColumnName", typeof(My.Project.Converter)]
[DynamoDBGlobalSecondaryIndexHashKey("My-index-name", Converter = typeof(My.Project.Converter)]
public int MyProperty { get; set; }
The error is in DynamoDbConversionUtils.GetPropertyConverter():
var propertyAttribute = propInfo.GetCustomAttributes(typeof(DynamoDBAttribute), true)
.OfType<DynamoDBPropertyAttribute>()
.SingleOrDefault();
Hi Howard,
Well, I'm not sure this would work even if you marked your property with just one of those attributes. Linq2DynamoDB doesn't require and doesn't support neither DynamoDBHashKey nor DynamoDBGlobalSecondaryIndexHashKey.
Are you sure you really need them? What for?
I had a table where one attribute was the table hash key as well as the hash key for a global secondary index. I tried commenting out the DynamoDBGlobalSecondaryIndexHashKey attribute, and instead got some other error (which I didn't note at the time, sorry, but I think it had do with DynamoDB not able to tell if I was querying using the primary key or the GSI). In the end, it turned out I didn't need that GSI, so we just dropped it, completely side-stepping this issue.
Still, you could fix the bug by finding the first DynamoDBAttribute that has a converter defined, since it doesn't make sense that a column would require two different converters.