Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object property cannot have >1 DynamoDBPropertyAttribute #32

Open
howcheng opened this issue Mar 10, 2016 · 2 comments
Open

Object property cannot have >1 DynamoDBPropertyAttribute #32

howcheng opened this issue Mar 10, 2016 · 2 comments

Comments

@howcheng
Copy link

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();
@scale-tone
Copy link
Owner

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?

@howcheng
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants