Convertitori - AWS Guida prescrittiva

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Convertitori

In alcuni casi, potrebbe essere necessario modificare o trasformare i dati durante il salvataggio o la lettura dal database DynamoDB. In questi scenari, puoi utilizzare l'interfaccia IPropertyConverter di Amazon.Dynamo. DBv2 DataModelnamespace, utilizzando un codice simile al seguente:

// Converts the null values of a string property to a valid string and vice versa. public class NullOrStringConverter : IPropertyConverter { // Called when creating the JSON / DynamoDB item from the model public DynamoDBEntry ToEntry(object value) { var entry = new Primitive { value = new DynamoDBNull() }; if(value != null) { entry.Value = value.ToString(); } return entry; } // Called when populating the model from the JSON / DynamoDB item public object FromEntry(DynamoDBEntry entry) { if(entry is DynamoDBNull) { return string.Empty; } else { return entry.ToString(); } } }

Utilizzo del convertitore nel modello:

[DynamoDBTable(“AppLibrary")] public class ProdApp { . . . [DynamoDBProperty (typeof(NullOrString))] public string AppConfigId { get; set; } . . . }