Skip to content

Moving from CRUD and EF Core to Cratis Chronicle

Cratis Chronicle records events and derives current state from them, rather than replacing a row whenever something changes. If you use EF Core, the main adoption decision is which changes need that history and which can stay as ordinary CRUD: create, read, update, and delete operations. You can use both approaches in the same application.

In CRUD, you store current state and update it; in Chronicle, you record what happened and derive current state from those facts. That derived state is a read model: data shaped for a query or screen, built from events instead of edited directly.

You know (CRUD / EF Core) In Chronicle
An entity with an identity An event source: the identity whose changes the events describe
INSERT a row Append a “created” event
UPDATE a column Append an event describing what changed (e.g. AddressChanged)
DELETE a row Append a domain event such as CustomerRemoved; erasure is a separate compliance operation
DbContext.SaveChanges() EventLog.Append(...)
SELECT / LINQ query A query over a read model built by a projection
A computed/denormalized view A purpose-built read model — make as many as you need
ALTER TABLE / EF migration Use an event type migration when an event’s shape changes; rebuild read models when their projection needs it
Optimistic concurrency token A concurrency scope or decision read that guards the append against intervening events

In a .NET application, you still use C# records and dependency injection. Your screens still query data and render results; they query read models rather than the event log itself. Keep EF Core and your existing database for data that only needs ordinary updates. Choosing Chronicle for one workflow does not require moving every table.

A customer row tells you the address now. An AddressChanged event also records that a move happened, so you can later derive a relocation count or rebuild a view of those changes. Choose events that describe business facts, such as CustomerRegistered and AccountClosed, rather than recording every column assignment.

A projection defines how those events become a read model. By default, Chronicle materializes that model, meaning it stores the derived result for queries. Processing happens after the append, so a successful write does not mean the stored view already includes it. For read-after-write, you can wait for processing or use a suitable passive read model, computed from events on demand. Read model consistency explains those choices. A fresh read alone does not guard a later write against another request.

Removing a customer from a screen need not remove the customer’s history. Your projection can react to a removal event and remove its read-model entry. A closed account also needs an explicit closing rule if later appends must be refused. For obligations that require erasing personal data, use Compliance rather than treating a removal event as erasure.

CRUD: update a row, then read it back. This is illustrative EF Core pseudocode, not a compiled example:

customer.Address = newAddress;
await db.SaveChangesAsync();
var current = await db.Customers.FindAsync(id);

With Chronicle, the address change becomes an event to append. The examples below illustrate that write and its read model; client APIs differ, so use your chosen client’s setup guide before applying them. First, define the event types:

using Cratis.Chronicle.Events;
[EventType]
public record CrudComparisonCustomerRegistered(string Name, string Address);
[EventType]
public record CrudComparisonAddressChanged(string Address);

View C# snippet source on GitHub

Then define a customer card for the screen. The projection maps events onto that card and counts address changes. The result need not mirror the old Customer entity:

using Cratis.Chronicle.Keys;
using Cratis.Chronicle.Projections.ModelBound;
[FromEvent<CrudComparisonCustomerRegistered>]
[FromEvent<CrudComparisonAddressChanged>]
public record CrudComparisonCustomerCard(
[Key] Guid Id,
string Name,
string Address,
[Count<CrudComparisonAddressChanged>] int TimesRelocated);

View C# snippet source on GitHub

In the .NET example, [FromEvent<T>] maps matching event properties onto the read model; TypeScript uses @fromEvent. The registration event supplies the name, and address-change events update the address. The count declaration retains something a row holding only the latest address would not tell you: how many changes occurred.

Now the write and the read-back:

using Cratis.Chronicle.Events;
public class CrudComparisonCustomerAddressUpdater(IEventStore eventStore)
{
public async Task<CrudComparisonCustomerCard> ChangeAddress(EventSourceId customerId, string newAddress)
{
await eventStore.EventLog.Append(customerId, new CrudComparisonAddressChanged(newAddress));
return await eventStore.ReadModels.GetInstanceById<CrudComparisonCustomerCard>(customerId);
}
}

View C# snippet source on GitHub

GetInstanceById retrieves the derived card, including TimesRelocated. For a materialized read model, that is the stored result, not a promise to replay the history on this call. Before relying on an immediate read-back, choose the consistency behavior that includes your append.

Start with a workflow where the sequence of changes answers a question the current row cannot. If you only need the latest value and have no use for replay or history, CRUD may remain the simpler choice. When to use event sourcing helps you make that decision before changing the storage model.

  • Get started to run the kernel and connect your chosen client.
  • Follow the tutorial to build an event-driven workflow and its read side.