Skip to content

Projection With FromAll

FromAll is a .NET declarative projection API that maps properties from every event considered by the projection, excluding child projection events by default. Other clients expose the same underlying concept through their every-event APIs configured to exclude children; see Projection With FromEvery for the full every-event feature set.

Use FromAll in .NET when the projection should express that a mapping belongs to the all-events portion of the projection definition. In Elixir, the same default (excluding child projection events) is what from_every does when :include_children is omitted. In TypeScript, call excludeChildProjections() on the fromEvery builder to get the same behavior.

Declarative FromAll
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;
[EventType]
public record UserCreatedDeclarativeAll(string Name, string Email);
[EventType]
public record UserEmailChangedDeclarativeAll(string Email);
public record UserProfileDeclarativeAll(
string Name,
string Email,
DateTimeOffset LastUpdated);
public class UserProfileDeclarativeAllProjection : IProjectionFor<UserProfileDeclarativeAll>
{
public void Define(IProjectionBuilderFor<UserProfileDeclarativeAll> builder) => builder
.From<UserCreatedDeclarativeAll>()
.From<UserEmailChangedDeclarativeAll>()
.FromAll(_ => _
.Set(m => m.LastUpdated)
.ToEventContextProperty(c => c.Occurred));
}
Map context fields with FromAll
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;
[EventType]
public record AccountTouchedDeclarativeAll(string Reason);
public record AccountAuditDeclarativeAll(
DateTimeOffset LastUpdated,
EventSequenceNumber LastEventSequence,
string LastCorrelationId);
public class AccountAuditDeclarativeAllProjection : IProjectionFor<AccountAuditDeclarativeAll>
{
public void Define(IProjectionBuilderFor<AccountAuditDeclarativeAll> builder) => builder
.From<AccountTouchedDeclarativeAll>()
.FromAll(_ => _
.Set(m => m.LastUpdated).ToEventContextProperty(c => c.Occurred)
.Set(m => m.LastEventSequence).ToEventContextProperty(c => c.SequenceNumber)
.Set(m => m.LastCorrelationId).ToEventContextProperty(c => c.CorrelationId));
}
Map event source id with FromAll
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;
[EventType]
public record AccountOpenedDeclarativeAll(string OwnerName);
public record AccountSummaryDeclarativeAll(
string AccountId,
string OwnerName);
public class AccountSummaryDeclarativeAllProjection : IProjectionFor<AccountSummaryDeclarativeAll>
{
public void Define(IProjectionBuilderFor<AccountSummaryDeclarativeAll> builder) => builder
.From<AccountOpenedDeclarativeAll>()
.FromAll(_ => _
.Set(m => m.AccountId)
.ToEventSourceId());
}

FromAll can sit beside event-specific From mappings. Use event-specific mappings for business state, and reserve FromAll for metadata that should update for every projected event.

Combine FromAll with event-specific mappings
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;
[EventType]
public record OrderCreatedDeclarativeAll(string OrderNumber);
[EventType]
public record OrderShippedDeclarativeAll(string TrackingNumber);
public record OrderDeclarativeAll(
string OrderNumber,
string Status,
DateTimeOffset LastModified);
public class OrderDeclarativeAllProjection : IProjectionFor<OrderDeclarativeAll>
{
public void Define(IProjectionBuilderFor<OrderDeclarativeAll> builder) => builder
.FromAll(_ => _
.Set(m => m.LastModified)
.ToEventContextProperty(c => c.Occurred))
.From<OrderCreatedDeclarativeAll>(_ => _
.Set(m => m.Status)
.ToValue("Placed"))
.From<OrderShippedDeclarativeAll>(_ => _
.Set(m => m.Status)
.ToValue("Shipped"));
}
APIUse it when
FromAllYou are using the .NET declarative projection API and want to express an all-events mapping.
FromEveryYou want the portable every-event concept, or you are using a client that exposes the concept under that name.

Prefer event context sources for audit fields because every event has the same context shape. Use event payload properties only when the event contracts intentionally share the same property.