Path: redb/redb.Examples/Examples/E001_SaveAsync.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Examples/Examples/E001_SaveAsync.cs
----
using System.Diagnostics;
using redb.Core;
using redb.Core.Models.Entities;
using redb.Examples.Models;
using redb.Examples.Output;
namespace redb.Examples.Examples;
///
/// Example: Create and save a new employee.
///
[ExampleMeta("E001", "SaveAsync - Create Employee", "CRUD",
ExampleTier.Free, 1, "SaveAsync", "Create", "CRUD")]
public class E001_SaveAsync : ExampleBase
{
public override async Task RunAsync(IRedbService redb)
{
var sw = Stopwatch.StartNew();
var employee = new RedbObject
{
name = "New Developer",
Props = new EmployeeProps
{
FirstName = "Alice",
LastName = "Johnson",
Age = 28,
Position = "Developer",
Department = "Engineering",
Salary = 85000m,
HireDate = DateTime.Today,
EmployeeCode = "EMP-NEW-001",
Skills = ["C#", "React", "SQL"]
}
};
var id = await redb.SaveAsync(employee);
sw.Stop();
return Ok("E001", "SaveAsync - Create Employee", ExampleTier.Free, sw.ElapsedMilliseconds,
[$"Created employee ID: {id}", $"Name: {employee.Props.FirstName} {employee.Props.LastName}"]);
}
}