简体   繁体   中英

DynamoDB Scan doesn't map to DynamoDBProperty correctly?

I'm having an issue where DynamoDB Scan doesn't seem to be mapping results back to the data class correctly. Here's some code:

[DynamoDBTable(TABLE_NAME)]
public class Settings
{
    public const string TABLE_NAME = "Settings";
    public const string PROPERTY_VALUE_INT = "I";

    [DynamoDBHashKey]
    public string K { get; set; }

    [DynamoDBProperty(PROPERTY_VALUE_INT)]
    public int ValueInt { get; set; }
}

I'm able to construct Settings objects and use PutItem to successfully add to the DB entries with fields "K" and "I". However, when I try to then Scan the results, the value of the "I" field does not get mapped into the "ValueInt" field of the Settings object (so the ValueInt field always defaults to 0). If I add an "I" variable to the Settings object, the Scan will map to that field correctly. Why doesn't Scan recognize the DynamoDBProperty Attribute?

Here's the Scan code:

AmazonDynamoDBConfig config = new AmazonDynamoDBConfig()
{
    ServiceURL = "http://dynamodb.us-east-2.amazonaws.com"
};
Client = new AmazonDynamoDBClient(config);
Context = new DynamoDBContext(Client);

List<Settings> settings = Context.Scan<Settings>().ToList();

Figured it out. The issue was that I was using the old AWSSDK package instead of the newer AWSSDK.Core and AWSSDK.DynamoDBv2 ones

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM