我已经在DynamoDB中创建了表,并且我想使用PocoDynamo对它们进行写操作。但是,我需要在运行时根据我运行的环境更改表名。我可以在查询时成功地这样做,如下所示:
private string _environment = "dev";
private IEnumerable<Television> Load()
{
var db = new PocoDynamo(_client);
var q = db.FromQuery<Television>(q => q.Id == 1);
Decorate(q, _environment);
return q.Exec();
}
private void Decorate<TPoco>(QueryExpression<TPoco> query, string decorator)
{
query.TableName = $"{decorator}-{query.TableName}";
}这很好用,但是我不知道如何在运行时使用Put和Delete来做到这一点。
有没有人知道这是否可能?
发布于 2018-01-31 17:24:55
我设法通过修改register中的元数据来解决这个问题:
var decorator = "production";
var db = new PocoDynamo(_client);
db.RegisterTable(typeof(Television));
var metaTableData = _pocoDb.GetTableMetadata(type);
metaTableData.Name = $"{decorator}-{metaTableData.Name}";然后Put和Delete工作正常:
// the following will add/delete items with table name "production-Television"
db.PutItems(televisions);
db.DeleteItems<Television>(televisionHashes);发布于 2018-05-25 06:30:31
您还可以将别名属性动态添加到类型中。
即。
entityType.AddAttributes(new AliasAttribute(alias));
db.RegisterTable(entityType);AddAttributes来自ServiceStack.Text PlatformExtensions
https://stackoverflow.com/questions/48401215
复制相似问题