Amazon DynamoDB · Create
Store every kind of value
What each .NET value becomes in DynamoDB, in two scenarios: numbers, text and flags; then dates, documents, lists and picklists.
Set up for this page
The scenarios build on the sample application: SampleContext.cs (the dbContext every sample is given); SampleOutput.cs (Step and Show, which print); SampleContext.Application.cs (dbContext.Service, the application's ARX service); SampleModel.cs (the DynamoDB layout and the schema catalog); SampleContext.Direct.cs (dbContext.Direct); DynamoDirectHelper.cs (the checks behind dbContext.Direct).
dbContext.Direct is the samples' own checking code on the plain driver, not part of ARX: leave it out of your application.
1 Numbers, text and flags
A product with numbers of every kind, a flag, bytes and a Guid.
Already in scope: service (ArxDynamoDbService)
var product = new ArxEntity("product");
product["sku"] = "SKU-D501";
product["name"] = "Camp stove";
product["stock"] = 42;
product["weight_kg"] = 1.25;
product["price"] = 89.99m;
product["is_active"] = true;
product["barcode"] = new byte[] { 0x01, 0x02, 0x03 };
product["supplier_ref"] = Guid.Parse("3f2504e0-4f89-41d3-9a0c-0305e82c3301");
await service.CreateAsync(product);
Console.WriteLine("created product SKU-D501");Check it in the database
A PartiQL statement: run it in NoSQL Workbench, or with aws dynamodb execute-statement --statement, after the code has run.
SELECT * FROM "product" WHERE "sku" = 'SKU-D501'Expect: stock 42, weight_kg 1.25, price 89.99, is_active true, supplier_ref "3f2504e0-4f89-41d3-9a0c-0305e82c3301".
2 Dates, documents, lists and picklists
An order with dates, an embedded address, a list of tags and a picklist value.
Already in scope: service (ArxDynamoDbService)
var order = new ArxEntity("sales_order");
order["customer_id"] = "C-D501";
order["order_number"] = "SO-D501";
order["ordered_on"] = "2026-11-09";
order["status"] = new ArxSelectionSetValue("OrderStatus", "OPEN");
order["placed_at"] = new DateTime(2026, 11, 9, 14, 30, 0, DateTimeKind.Utc);
order["ship_by"] = new DateOnly(2026, 11, 12);
order["ship_to"] = new ArxJsonB { SerializedValue = "{\"street\":\"1 Harbour Road\",\"city\":\"Porto\"}" };
order["tags"] = new[] { "gift", "express" };
await service.CreateAsync(order);
Console.WriteLine("created order SO-D501");Check it in the database
A PartiQL statement: run it in NoSQL Workbench, or with aws dynamodb execute-statement --statement, after the code has run.
SELECT "placed_at", "ship_by", "ship_to", "tags", "status" FROM "crm" WHERE "PK" = 'CUSTOMER#C-D501' AND "SK" = 'ORDER#SO-D501'Expect: placed_at "2026-11-09T14:30:00.0000000Z", ship_by "2026-11-12", ship_to a map with city "Porto", tags ["gift", "express"], status "OPEN".
Good to know
- Numbers are N (up to 38 digits); NaN and infinity are refused. Text is S, booleans BOOL, bytes B, a Guid its text.
- Dates are sortable ISO 8601 text in UTC with seven fraction digits (an Unspecified DateTime is taken as UTC); a DateOnly is
yyyy-MM-dd. ArxJsonBis a map; a list or an array is a list.
See also
Run the complete sample
The code above comes from one program, built in a fresh project and run against the database. To run it yourself, here is every file and step.
The program, its files and how to run it
Run it locally
- .NET SDK: .NET SDK 10.0.100 or later 10.0.x (target
net10.0). - Create the project:
Terminal dotnet new console -n ArxSample -f net10.0 cd ArxSample - Install the packages:
Terminal dotnet add package ARX.SDK.DynamoDb --version 1.0.0-rc.1 - Database: a Amazon DynamoDB, or DynamoDB Local for development (tested with DynamoDB Local 2.5.2) database with the sample schema.
- Configuration: set
ARX_SAMPLES_DYNAMODBto its connection string. Nothing is hard-coded. - Source code: add the files of the sample application this sample uses (
SampleContext.cs,SampleOutput.cs,SampleContext.Application.cs,SampleModel.cs,SampleContext.Direct.cs,DynamoDirectHelper.cs), then replaceProgram.csand add the other file below, with the file names shown. - Run it:
Terminal dotnet run - Expected output: below.
The files
Runs the sample. Generated for this page; it reads the connection string from the environment and first remakes the sample database from sample-schema.json.
using ArxSamples.DynamoDb;
using ArxSamples.DynamoDb.Operations.Create.RealCases;
// The connection string comes from the environment, never from the code (see "Configure the connection").
var connectionString = Environment.GetEnvironmentVariable("ARX_SAMPLES_DYNAMODB")
?? throw new InvalidOperationException("Set the ARX_SAMPLES_DYNAMODB environment variable to your Amazon DynamoDB connection string.");
var dbContext = new SampleContext(connectionString);
// Every run starts from the sample data: this deletes and makes again what sample-schema.json lists
// (save the file in the project folder, see Get started).
await dbContext.Direct.ResetAsync();
await new RealCase1_EveryDataType().RunAsync(dbContext);
The sample, as it is in the repository.
using ARX.SDK.DynamoDb.Services;
using ARX.SDK.Models;
using ARX.SDK.Services;
using static ArxSamples.DynamoDb.SampleOutput;
namespace ArxSamples.DynamoDb.Operations.Create.RealCases;
/// <summary>
/// What each .NET value becomes in DynamoDB, in two scenarios: numbers, text and flags; then dates, documents, lists
/// and picklists.
/// </summary>
/// <remarks>
/// <list type="bullet">
/// <item>Numbers are N (up to 38 digits); NaN and infinity are refused. Text is S, booleans BOOL, bytes B, a Guid its text.</item>
/// <item>Dates are sortable ISO 8601 text in UTC with seven fraction digits (an Unspecified DateTime is taken as UTC);
/// a DateOnly is <c>yyyy-MM-dd</c>.</item>
/// <item><see cref="ArxJsonB"/> is a map; a list or an array is a list.</item>
/// </list>
/// </remarks>
public sealed class RealCase1_EveryDataType : ISample
{
public string Name => "create-real-1-every-data-type";
public string Title => "Store every kind of value";
public async Task RunAsync(SampleContext dbContext)
{
await Scenario1_NumbersTextAndFlagsAsync(dbContext.Service);
await Scenario2_DatesDocumentsListsAndPicklistsAsync(dbContext.Service);
}
/// <summary>1. A product with numbers of every kind, a flag, bytes and a Guid.</summary>
private static async Task Scenario1_NumbersTextAndFlagsAsync(ArxDynamoDbService service)
{
Step("1. Numbers, text and flags");
var product = new ArxEntity("product");
product["sku"] = "SKU-D501";
product["name"] = "Camp stove";
product["stock"] = 42;
product["weight_kg"] = 1.25;
product["price"] = 89.99m;
product["is_active"] = true;
product["barcode"] = new byte[] { 0x01, 0x02, 0x03 };
product["supplier_ref"] = Guid.Parse("3f2504e0-4f89-41d3-9a0c-0305e82c3301");
await service.CreateAsync(product);
Show("created product SKU-D501");
/* ===========================================================
* [DIRECT QUERY CHECK]
* -----------------------------------------------------------
* SELECT * FROM "product" WHERE "sku" = 'SKU-D501'
* -- Expect: stock 42, weight_kg 1.25, price 89.99, is_active true, supplier_ref "3f2504e0-4f89-41d3-9a0c-0305e82c3301".
* ===========================================================
*/
}
/// <summary>2. An order with dates, an embedded address, a list of tags and a picklist value.</summary>
private static async Task Scenario2_DatesDocumentsListsAndPicklistsAsync(ArxDynamoDbService service)
{
Step("2. Dates, documents, lists and picklists");
var order = new ArxEntity("sales_order");
order["customer_id"] = "C-D501";
order["order_number"] = "SO-D501";
order["ordered_on"] = "2026-11-09";
order["status"] = new ArxSelectionSetValue("OrderStatus", "OPEN");
order["placed_at"] = new DateTime(2026, 11, 9, 14, 30, 0, DateTimeKind.Utc);
order["ship_by"] = new DateOnly(2026, 11, 12);
order["ship_to"] = new ArxJsonB { SerializedValue = "{\"street\":\"1 Harbour Road\",\"city\":\"Porto\"}" };
order["tags"] = new[] { "gift", "express" };
await service.CreateAsync(order);
Show("created order SO-D501");
/* ===========================================================
* [DIRECT QUERY CHECK]
* -----------------------------------------------------------
* SELECT "placed_at", "ship_by", "ship_to", "tags", "status" FROM "crm" WHERE "PK" = 'CUSTOMER#C-D501' AND "SK" = 'ORDER#SO-D501'
* -- Expect: placed_at "2026-11-09T14:30:00.0000000Z", ship_by "2026-11-12", ship_to a map with city "Porto", tags ["gift", "express"], status "OPEN".
* ===========================================================
*/
}
}
Expected output
What dotnet run printed when the sample was verified, on a freshly created sample schema. Ids differ when the tables already hold rows.
> 1. Numbers, text and flags
created product SKU-D501
> 2. Dates, documents, lists and picklists
created order SO-D501