Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
Convertisseurs
Dans certains cas, vous devrez peut-être modifier ou transformer des données lors de l'enregistrement ou de la lecture dans la base de données DynamoDB. Dans ces scénarios, vous pouvez utiliser l'interface IPropertyConverter d'Amazon.Dynamo. DBv2 DataModelespace de noms, en utilisant un code similaire au suivant :
// 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(); } } }
Utilisation du convertisseur dans le modèle :
[DynamoDBTable(“AppLibrary")] public class ProdApp { . . . [DynamoDBProperty (typeof(NullOrString))] public string AppConfigId { get; set; } . . . }