4

Using the AWS SDK for .net I'm trying to save a list of non-unique strings. This list isn't the primary hash or anything, I just want to be able to reference them by their order and include duplicates.

The model

[DynamoDBTable("RMS.Accounts")]
public class Account
{
    [DynamoDBHashKey]
    public int Id { get; set; } 
    public string SomeValue { get; set; }
    public List<string> MoreValues{ get; set; }

    public Account()
    {
        // set default value
        MoreValues= new List<string>();
    }
}

The controller

Account account = new Account();
account.SomeValue = "testvalue";
account.MoreValues.Add("value1");
account.MoreValues.Add("value1");

var client = new AmazonDynamoDBClient();
var context = new DynamoDBContext(client);
context.Save(account, new DynamoDBOperationConfig() { SkipVersionCheck = true });

When I run the above code I get:

"An exception of type 'Amazon.DynamoDBv2.AmazonDynamoDBException' occurred in Apfm.RMS.Common.dll but was not handled in user code

Additional information: One or more parameter values were invalid: Input collection [value1, value1] contains duplicates.

I've read everything I can get my hands on but can't figure out a way around this. Maybe I need to use some other kind of collection so Dynamo knows the items don't need to be unique.

1
  • This seems like more of an issue with the .NET SDK because DynamoDB has support for list types. Commented Mar 26, 2015 at 3:53

1 Answer 1

13

Take a look at this blog post that details how the .NET SDK converts .NET types such as List<string> or HashSet<string> into DynamoDB data types.

In short, the SDK defaults to V1 conversion schema, where List<string> is stored as DynamoDB SS type, which does not allow duplicate items. You want to switch to using the V2 conversion schema. This can be done in multiple ways:

1.Set the conversion for the application:

<configSections> <section name="aws" type="Amazon.AWSSection, AWSSDK"/> </configSections> <aws> <dynamoDB conversionSchema="V2" /> </aws>

2.Set the conversion on the context:

var context = new DynamoDBContext(client, new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 });

3.Set the conversion on the operation:

context.Save(account, new DynamoDBOperationConfig { Conversion = DynamoDBEntryConversion.V2 });

The approaches are listed as progressively granular. Switching conversion schemas will change how some types are stored (the blog post goes into a bit of detail on this), so take this into consideration.

Sign up to request clarification or add additional context in comments.

1 Comment

@Pavel Safronov. I read the blog above and it is nt clear to me. Can we switch from V1 to V2 and old apps that use V1 would work just as before. It is not clear to me if V2 is backwards compatible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.