Skip to content

Model-bound projections: choose an event sequence

A model-bound projection reads events from one event sequence. In .NET, Chronicle uses the event log unless the model selects another sequence or its event types imply an inbox. Set [EventSequence] on the read model when you need to choose the source explicitly:

using Cratis.Chronicle.EventSequences;
using Cratis.Chronicle.Keys;
using Cratis.Chronicle.Projections.ModelBound;
[EventType]
public record MbEventSeqOrderPlaced(decimal Amount);
[EventSequence("custom-sequence")]
public record MbEventSeqOrderSummary(
[Key]
Guid Id,
[SetFrom<MbEventSeqOrderPlaced>(nameof(MbEventSeqOrderPlaced.Amount))]
decimal TotalAmount);

View C# snippet source on GitHub

The model-bound attribute selects custom-sequence for the read model. A separate fluent projection makes the same choice with FromEventSequence:

using Cratis.Chronicle.EventSequences;
using Cratis.Chronicle.Projections;
[EventType]
public record MbEventSeqFluentOrderPlaced(decimal Amount);
public class MbEventSeqFluentOrderProjection : IProjectionFor<MbEventSeqFluentOrderSummary>
{
public void Define(IProjectionBuilderFor<MbEventSeqFluentOrderSummary> builder) => builder
.FromEventSequence(new EventSequenceId("custom-sequence"))
.From<MbEventSeqFluentOrderPlaced>(_ => _
.Set(m => m.TotalAmount).To(e => e.Amount));
}
public class MbEventSeqFluentOrderSummary
{
public decimal TotalAmount { get; set; }
}

View C# snippet source on GitHub

The examples use .NET attributes. For TypeScript model-bound models, use @eventSequence('custom-sequence'); the event-sequence argument on @projection applies to fluent projections. Elixir takes event_sequence: on use Chronicle.ReadModels.ReadModel; Kotlin and Java accept eventSequence on @Projection.

Use [EventLog] to select the event log explicitly and bypass automatic inbox routing:

using Cratis.Chronicle.EventSequences;
using Cratis.Chronicle.Keys;
[EventType]
public record MbEventSeqLocalEvent(string Data);
[EventLog]
public record MbEventSeqLocalSnapshot(
[Key]
Guid Id,
[SetFrom<MbEventSeqLocalEvent>(nameof(MbEventSeqLocalEvent.Data))]
string Data);

View C# snippet source on GitHub

Without an explicit sequence, the .NET client checks the event types in the projection’s From mappings. If their [EventStore] metadata names a different event store, Chronicle selects that store’s inbox sequence. You do not need an [EventSequence] annotation for this routing.

If the metadata names the current event store, or no store is specified, Chronicle selects the event log. The client rejects a model whose source event types name more than one event store.

  • When you need to read from a specific sequence other than the inferred one
  • To suppress automatic inbox routing for a projection that handles foreign events
  • For projections that target a specialized or partitioned event stream

The old [FromEventSequence] attribute has been removed. Use [EventSequence] instead. Once the source is selected, use From Every Event for mappings across handled events or From All to subscribe to every event type in that sequence.