2

Using Dynamo Object Persistence Modal with C#

Consider the object

class SomeObject{
 [DynamoDBHashKey]
 public string A {get; set;}

 [DynamoDBGlobalSecondaryIndexHashKey]
 [DynamoDBRangeKey]
 public string B {get; set;}
}

The below code works fine with an object has to be queried in a table

 _dynamoDbContext.LoadAsync<SomeObject>(new SomeObject(){ A = "test", B = "test" })

I have a secondary index on the same table and would like to retrieve the value

_dynamoDbContext.LoadAsync<SomeObject>(new SomeObject(){ B = "test" }, new DynamoDBOperationConfig()
        {
            IndexName = "Some_Index_Name"
        };)

I cant find any documentation on this, but expected this to work.

I know it can be done with QueryAsync, but is there a way it works with LoadAsync ?

Sunny
  • 932
  • 8
  • 22
  • Stumbled on this a few minutes ago as well when trying to implement a repository. This sounds like a bug to me to be quite honest. It seems that the `IndexName` property is completely ignored for `LoadAsync`, meaning it is always attempting to fetch using the primary index. In your case, looks like it just doesn't return anything. In my case, since the primary and secondary index keys had different types, it actually results in an `InvalidCastException`. – julealgon Nov 20 '20 at 20:11
  • Created [an issue](https://github.com/aws/aws-sdk-net/issues/1748) to track this in their repository. – julealgon Nov 20 '20 at 20:29

0 Answers0