我正在使用.Net对象持久性模型将项目存储到Dynamo DB中。它在我的机器上工作正常,但是当我将项目发布到AWS lambda服务时,没有任何东西存储到数据库中。
请帮忙。
答案 0 :(得分:1)
我通过设置" IgnoreValue"来解决问题。在DynamoDBContextConfig中为true。从代码中删除context.SaveAsync(model)。下面是工作代码示例。
[DynamoDBTable("User")]
public class UserModel
{
[DynamoDBHashKey]
public int ID { get; set; }
[DynamoDBRangeKey]
public string Class { get; set; }
[DynamoDBProperty]
public string Name { get; set; }
}
在初始化上面的模型之后是将项目插入DynamoDB的代码。
public async Task InsertRecord(UserModel model)
{
try
{
using( var context = new DynamoDBContext(client, new DynamoDBContextConfig { ConsistentRead = true, SkipVersionCheck = true,IgnoreNullValues=true }))
{
var dataContext = context.CreateBatchWrite<UserModel>();
dataContext.AddPutItem(model);
await dataContext.ExecuteAsync();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException.StackTrace.ToString());
}
}