1

我已经在 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 执行此操作。

有人知道这是否可能吗?

4

2 回答 2

2

我设法通过更改寄存器中的元数据来解决这个问题:

var decorator = "production";
var db = new PocoDynamo(_client);
db.RegisterTable(typeof(Television));
var metaTableData = _pocoDb.GetTableMetadata(type);
metaTableData.Name = $"{decorator}-{metaTableData.Name}";

然后放置和删除工作正常:

// the following will add/delete items with table name "production-Television"
db.PutItems(televisions);
db.DeleteItems<Television>(televisionHashes);
于 2018-01-31T09:24:55.053 回答
2

您还可以为类型动态添加别名属性。

IE。

entityType.AddAttributes(new AliasAttribute(alias));
db.RegisterTable(entityType);

AddAttributes 来自 ServiceStack.Text PlatformExtensions

于 2018-05-24T22:30:30.740 回答