Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon dynamodb 使用.NET AWS SDK对象持久性模型保存项目时动态忽略属性_Amazon Dynamodb_Dynamodb Queries - Fatal编程技术网

Amazon dynamodb 使用.NET AWS SDK对象持久性模型保存项目时动态忽略属性

Amazon dynamodb 使用.NET AWS SDK对象持久性模型保存项目时动态忽略属性,amazon-dynamodb,dynamodb-queries,Amazon Dynamodb,Dynamodb Queries,使用.NET对象持久性模型保存项目时,是否可以动态忽略某些属性 我不想用DynamoDBIgnore装饰我的类属性,因为有时我确实想保存在这些类中所做的更改 我尝试将IgnoreNullValues设置为true,但是在使用批保存项目时,这不起作用 代码如下: using (var context = new DynamoDBContext(awsClient, _dynamoDbContextConfig)) { var batch = context.CreateBatchWrite

使用.NET对象持久性模型保存项目时,是否可以动态忽略某些属性

我不想用DynamoDBIgnore装饰我的类属性,因为有时我确实想保存在这些类中所做的更改

我尝试将IgnoreNullValues设置为true,但是在使用批保存项目时,这不起作用

代码如下:

using (var context = new DynamoDBContext(awsClient, _dynamoDbContextConfig))
{
    var batch = context.CreateBatchWrite<T>(
        new DynamoDBOperationConfig {SkipVersionCheck = true, IgnoreNullValues = true});

    batch.AddPutItems(items);

    await context.ExecuteBatchWriteAsync(new BatchWrite[] {batch});
}
使用(var context=new DynamoDBContext(awsClient,_dynamoDbContextConfig))
{
var batch=context.CreateBatchWrite(
新的DynamodBoOperationConfig{SkipVersionCheck=true,IgnoreNullValues=true});
批次.添加PutItems(项目);
wait context.ExecuteBatchWriteAsync(新的BatchWrite[]{batch});
}
我应该使用较低级别的API来实现这一点吗?

较低级别的API(通过IAmazonDynamoDB/Amazondynamodb客户端公开)是迄今为止我发现的唯一更新现有DynamoDB文档的单个属性的方法

这方面的一个例子是:

var updateItemRequest = new UpdateItemRequest
{
    TableName = "search_log_table",
    Key = new Dictionary<string, AttributeValue>
    {
        {"PK", new AttributeValue("pk_value")},
        {"SK", new AttributeValue("sk_value")}
    },
    UpdateExpression = $"SET SearchCount = if_not_exists(SearchCount, :start) + :inc",
    ExpressionAttributeValues = new Dictionary<string, AttributeValue>
    {
        {":start", new AttributeValue {N = "0"}},
        {":inc", new AttributeValue {N = "1"}}
    },
    ReturnValues = "UPDATED_NEW"
};

// _client is an instance of IAmazonDynamoDB 
return _client.UpdateItemAsync(updateItemRequest); 
var updateItemRequest=new updateItemRequest
{
TableName=“搜索日志表”,
关键字=新字典
{
{“PK”,新属性值(“PK_值”)},
{“SK”,新属性值(“SK_值”)}
},
UpdateExpression=$“设置SearchCount=如果不存在(SearchCount,:start)+:inc”,
ExpressionAttributeValues=新字典
{
{”:开始,新属性值{N=“0”},
{“:inc”,新属性值{N=“1”}
},
ReturnValues=“更新的\新的”
};
//\u客户端是IAmazonDynamoDB的一个实例
返回_client.UpdateItemAsync(updateItemRequest);
这将插入一条新记录,如果不存在,则插入一条新记录,其中包含
PK=“PK\u值”,SK=“SK\u值”
。 语句
UpdateExpression=$“SET SearchCount=if_not_存在(SearchCount,:start)+:inc
第一次将
SearchCount
设置为1,并在每次后续调用时将属性递增1