FromEvery: update audit fields from handled events
FromEvery updates a read model property whenever the projection processes a handled event. Use it to maintain a last-modified timestamp or identify the operation that last changed the model without repeating the mapping for each event type.
An event-specific mapping runs only for its declared event type. An every-event mapping runs across the projection’s handled types; it does not subscribe to unrelated types in the sequence. Use From All when you need that wider subscription.
Map Event Context
Section titled “Map Event Context”Event context is the metadata carried alongside an event, such as occurrence time, sequence number, and correlation id. Its shared shape lets you maintain audit fields without requiring unrelated event payloads to contain the same properties:
using Cratis.Chronicle.Events;using Cratis.Chronicle.Keys;using Cratis.Chronicle.Projections.ModelBound;
[EventType]public record InventoryProductRegisteredForEvery(string ProductName);
[EventType]public record InventoryItemsAdjustedForEvery(int Quantity);
[FromEvent<InventoryProductRegisteredForEvery>][FromEvent<InventoryItemsAdjustedForEvery>]public record InventoryStatusFromEvery( [Key] Guid Id, string ProductName, [FromEvery(contextProperty: nameof(EventContext.Occurred))] DateTimeOffset LastUpdated);import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.projections.FromEventimport io.cratis.chronicle.projections.FromEveryimport io.cratis.chronicle.readModels.ReadModel
@EventTypedata class InventoryProductRegisteredForEvery(val productName: String)
@EventTypedata class InventoryItemsAdjustedForEvery(val quantity: Int)
@ReadModel@FromEvent(InventoryProductRegisteredForEvery::class)@FromEvent(InventoryItemsAdjustedForEvery::class)data class InventoryStatusFromEvery( val productName: String = "",
@FromEvery(contextProperty = "occurred") val lastUpdated: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.projections.FromEvent;import io.cratis.chronicle.projections.FromEvery;import io.cratis.chronicle.readModels.ReadModel;
@EventTyperecord InventoryProductRegisteredForEvery(String productName) {}
@EventTyperecord InventoryItemsAdjustedForEvery(int quantity) {}
@ReadModel@FromEvent(eventType = InventoryProductRegisteredForEvery.class)@FromEvent(eventType = InventoryItemsAdjustedForEvery.class)class InventoryStatusFromEvery { public String productName = "";
@FromEvery(contextProperty = "occurred") public String lastUpdated = "";}defmodule MyApp.Events.InventoryProductRegisteredForEvery do use Cratis.Chronicle.Events.EventType, id: "inventory-product-registered-for-every-v1"
defstruct [:product_name]end
defmodule MyApp.Events.InventoryItemsAdjustedForEvery do use Cratis.Chronicle.Events.EventType, id: "inventory-items-adjusted-for-every-v1"
defstruct [:quantity]end
defmodule MyApp.ReadModels.InventoryStatusFromEvery do use Cratis.Chronicle.ReadModels.ReadModel
alias MyApp.Events.{InventoryItemsAdjustedForEvery, InventoryProductRegisteredForEvery}
defstruct [:id, :product_name, :last_updated]
from InventoryProductRegisteredForEvery, set: [ id: :event_source_id, product_name: :product_name ]
from InventoryItemsAdjustedForEvery
from_every set: [last_updated: :occurred]endimport { eventType, fromEvent, fromEvery } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()export class InventoryProductRegisteredForEvery { @field(String) readonly productName: string;
constructor(productName: string) { this.productName = productName; }}
@eventType()export class InventoryItemsAdjustedForEvery { @field(Number) readonly quantity: number;
constructor(quantity: number) { this.quantity = quantity; }}
@fromEvent(InventoryProductRegisteredForEvery)@fromEvent(InventoryItemsAdjustedForEvery)export class InventoryStatusFromEvery { @field(String) productName = '';
@fromEvery(undefined, 'occurred') lastUpdated = new Date();}Map more than one context field when readers need to know both when the model changed and which operation changed it. These fields describe the latest handled event, not a history of changes:
using Cratis.Chronicle.Events;using Cratis.Chronicle.Keys;using Cratis.Chronicle.Projections.ModelBound;
[EventType]public record AuditableInventoryChangedForEvery(string Reason);
[FromEvent<AuditableInventoryChangedForEvery>]public record AuditableInventoryStatusFromEvery( [Key] Guid Id, [FromEvery(contextProperty: nameof(EventContext.Occurred))] DateTimeOffset LastModified, [FromEvery(contextProperty: nameof(EventContext.SequenceNumber))] EventSequenceNumber LastEventSequence, [FromEvery(contextProperty: nameof(EventContext.CorrelationId))] string LastCorrelationId);import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.projections.FromEventimport io.cratis.chronicle.projections.FromEveryimport io.cratis.chronicle.readModels.ReadModel
@EventTypedata class AuditableInventoryChangedForEvery(val reason: String)
@ReadModel@FromEvent(AuditableInventoryChangedForEvery::class)data class AuditableInventoryStatusFromEvery( @FromEvery(contextProperty = "occurred") val lastModified: String = "",
@FromEvery(contextProperty = "sequenceNumber") val lastEventSequence: String = "",
@FromEvery(contextProperty = "correlationId") val lastCorrelationId: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.projections.FromEvent;import io.cratis.chronicle.projections.FromEvery;import io.cratis.chronicle.readModels.ReadModel;
@EventTyperecord AuditableInventoryChangedForEvery(String reason) {}
@ReadModel@FromEvent(eventType = AuditableInventoryChangedForEvery.class)class AuditableInventoryStatusFromEvery { @FromEvery(contextProperty = "occurred") public String lastModified = "";
@FromEvery(contextProperty = "sequenceNumber") public String lastEventSequence = "";
@FromEvery(contextProperty = "correlationId") public String lastCorrelationId = "";}defmodule MyApp.Events.AuditableInventoryChangedForEvery do use Cratis.Chronicle.Events.EventType, id: "auditable-inventory-changed-for-every-v1"
defstruct [:reason]end
defmodule MyApp.ReadModels.AuditableInventoryStatusFromEvery do use Cratis.Chronicle.ReadModels.ReadModel
alias MyApp.Events.AuditableInventoryChangedForEvery
defstruct [:id, :last_modified, :last_event_sequence, :last_correlation_id]
from AuditableInventoryChangedForEvery, set: [id: :event_source_id]
from_every set: [ last_modified: :occurred, last_event_sequence: "$context.sequenceNumber", last_correlation_id: "$context.correlationId" ]endimport { eventType, fromEvent, fromEvery } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()export class AuditableInventoryChangedForEvery { @field(String) readonly reason: string;
constructor(reason: string) { this.reason = reason; }}
@fromEvent(AuditableInventoryChangedForEvery)export class AuditableInventoryStatusFromEvery { @fromEvery(undefined, 'occurred') lastModified = new Date();
@fromEvery(undefined, 'sequenceNumber') @field(Number) lastEventSequence = 0n;
@fromEvery(undefined, 'correlationId') lastCorrelationId = '';}Map Event Payload Properties
Section titled “Map Event Payload Properties”Every-event mappings can also read from event payload properties. Use this only when each event in the projection carries the same property name and compatible value type.
using Cratis.Chronicle.Events;using Cratis.Chronicle.Keys;using Cratis.Chronicle.Projections.ModelBound;
public enum OrderStateFromEvery{ New, Confirmed, Shipped}
[EventType]public record OrderConfirmedForEvery(OrderStateFromEvery Status);
[EventType]public record OrderShippedForEvery(OrderStateFromEvery Status);
[FromEvent<OrderConfirmedForEvery>][FromEvent<OrderShippedForEvery>]public record OrderStatusFromEvery( [Key] Guid Id, [FromEvery(property: nameof(OrderConfirmedForEvery.Status))] OrderStateFromEvery CurrentStatus);import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.projections.FromEventimport io.cratis.chronicle.projections.FromEveryimport io.cratis.chronicle.readModels.ReadModel
enum class OrderStateFromEvery { New, Confirmed, Shipped}
@EventTypedata class OrderConfirmedForEvery(val status: OrderStateFromEvery)
@EventTypedata class OrderShippedForEvery(val status: OrderStateFromEvery)
@ReadModel@FromEvent(OrderConfirmedForEvery::class)@FromEvent(OrderShippedForEvery::class)data class OrderStatusFromEvery( @FromEvery(property = "status") val currentStatus: OrderStateFromEvery = OrderStateFromEvery.New)import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.projections.FromEvent;import io.cratis.chronicle.projections.FromEvery;import io.cratis.chronicle.readModels.ReadModel;
enum OrderStateFromEvery { New, Confirmed, Shipped}
@EventTyperecord OrderConfirmedForEvery(OrderStateFromEvery status) {}
@EventTyperecord OrderShippedForEvery(OrderStateFromEvery status) {}
@ReadModel@FromEvent(eventType = OrderConfirmedForEvery.class)@FromEvent(eventType = OrderShippedForEvery.class)class OrderStatusFromEvery { @FromEvery(property = "status") public OrderStateFromEvery currentStatus = OrderStateFromEvery.New;}defmodule MyApp.Events.OrderConfirmedForEvery do use Cratis.Chronicle.Events.EventType, id: "order-confirmed-for-every-v1"
defstruct [:status]end
defmodule MyApp.Events.OrderShippedForEvery do use Cratis.Chronicle.Events.EventType, id: "order-shipped-for-every-v1"
defstruct [:status]end
defmodule MyApp.ReadModels.OrderStatusFromEvery do use Cratis.Chronicle.ReadModels.ReadModel
alias MyApp.Events.{OrderConfirmedForEvery, OrderShippedForEvery}
defstruct [:id, :current_status]
from OrderConfirmedForEvery, set: [id: :event_source_id]
from OrderShippedForEvery
from_every set: [current_status: :status]endimport { eventType, fromEvent, fromEvery } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
enum OrderStateFromEvery { New = 'New', Confirmed = 'Confirmed', Shipped = 'Shipped'}
@eventType()export class OrderConfirmedForEvery { @field(String) readonly status: OrderStateFromEvery;
constructor(status: OrderStateFromEvery) { this.status = status; }}
@eventType()export class OrderShippedForEvery { @field(String) readonly status: OrderStateFromEvery;
constructor(status: OrderStateFromEvery) { this.status = status; }}
@fromEvent(OrderConfirmedForEvery)@fromEvent(OrderShippedForEvery)export class OrderStatusFromEvery { @fromEvery('status') currentStatus = OrderStateFromEvery.New;}If a client supports convention-based property mapping, omitting the source property uses the read model property name.
using Cratis.Chronicle.Events;using Cratis.Chronicle.Keys;using Cratis.Chronicle.Projections.ModelBound;
[EventType]public record ProductRenamedForEveryConvention(string Name, int Version);
[EventType]public record ProductPriceChangedForEveryConvention(decimal Price, int Version);
[FromEvent<ProductRenamedForEveryConvention>][FromEvent<ProductPriceChangedForEveryConvention>]public record ProductVersionFromEveryConvention( [Key] Guid Id, string Name, decimal Price, [FromEvery] int Version);import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.projections.FromEventimport io.cratis.chronicle.projections.FromEveryimport io.cratis.chronicle.readModels.ReadModel
@EventTypedata class ProductRenamedForEveryConvention(val name: String, val version: Int)
@EventTypedata class ProductPriceChangedForEveryConvention(val price: Double, val version: Int)
@ReadModel@FromEvent(ProductRenamedForEveryConvention::class)@FromEvent(ProductPriceChangedForEveryConvention::class)data class ProductVersionFromEveryConvention( val name: String = "", val price: Double = 0.0,
@FromEvery val version: Int = 0)import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.projections.FromEvent;import io.cratis.chronicle.projections.FromEvery;import io.cratis.chronicle.readModels.ReadModel;
@EventTyperecord ProductRenamedForEveryConvention(String name, int version) {}
@EventTyperecord ProductPriceChangedForEveryConvention(double price, int version) {}
@ReadModel@FromEvent(eventType = ProductRenamedForEveryConvention.class)@FromEvent(eventType = ProductPriceChangedForEveryConvention.class)class ProductVersionFromEveryConvention { public String name = ""; public double price = 0.0;
@FromEvery public int version = 0;}defmodule MyApp.Events.ProductRenamedForEveryConvention do use Cratis.Chronicle.Events.EventType, id: "product-renamed-for-every-convention"
defstruct name: "", version: 0end
defmodule MyApp.Events.ProductPriceChangedForEveryConvention do use Cratis.Chronicle.Events.EventType, id: "product-price-changed-for-every-convention"
defstruct price: 0.0, version: 0end
defmodule MyApp.ReadModels.ProductVersionFromEveryConvention do use Cratis.Chronicle.ReadModels.ReadModel
defstruct id: nil, name: nil, price: 0.0, version: 0
from MyApp.Events.ProductRenamedForEveryConvention, set: [id: :event_source_id]
from MyApp.Events.ProductPriceChangedForEveryConvention
from_every set: [version: :version]endimport { eventType, fromEvent, fromEvery } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()export class ProductRenamedForEveryConvention { @field(String) readonly name: string; @field(Number) readonly version: number;
constructor(name: string, version: number) { this.name = name; this.version = version; }}
@eventType()export class ProductPriceChangedForEveryConvention { @field(Number) readonly price: number; @field(Number) readonly version: number;
constructor(price: number, version: number) { this.price = price; this.version = version; }}
@fromEvent(ProductRenamedForEveryConvention)@fromEvent(ProductPriceChangedForEveryConvention)export class ProductVersionFromEveryConvention { @field(String) name = ''; @field(Number) price = 0;
@fromEvery() version = 0;}Combine With Event-Specific Mappings
Section titled “Combine With Event-Specific Mappings”Keep business changes in event-specific mappings and share the audit mapping across them. Chronicle applies both while processing the event:
using Cratis.Chronicle.Events;using Cratis.Chronicle.Keys;using Cratis.Chronicle.Projections.ModelBound;
[EventType]public record UserRegisteredForEvery(string Name, string Email);
[EventType]public record UserNameChangedForEvery(string NewName);
[EventType]public record UserEmailChangedForEvery(string NewEmail);
[FromEvent<UserRegisteredForEvery>][FromEvent<UserNameChangedForEvery>][FromEvent<UserEmailChangedForEvery>]public record UserProfileFromEvery( [Key] Guid Id, [SetFrom<UserRegisteredForEvery>(nameof(UserRegisteredForEvery.Name))] [SetFrom<UserNameChangedForEvery>(nameof(UserNameChangedForEvery.NewName))] string Name, [SetFrom<UserRegisteredForEvery>(nameof(UserRegisteredForEvery.Email))] [SetFrom<UserEmailChangedForEvery>(nameof(UserEmailChangedForEvery.NewEmail))] string Email, [FromEvery(contextProperty: nameof(EventContext.Occurred))] DateTimeOffset LastUpdated);import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.projections.FromEventimport io.cratis.chronicle.projections.FromEveryimport io.cratis.chronicle.projections.SetFromimport io.cratis.chronicle.readModels.ReadModel
@EventTypedata class UserRegisteredForEvery(val name: String, val email: String)
@EventTypedata class UserNameChangedForEvery(val newName: String)
@EventTypedata class UserEmailChangedForEvery(val newEmail: String)
@ReadModel@FromEvent(UserRegisteredForEvery::class)@FromEvent(UserNameChangedForEvery::class)@FromEvent(UserEmailChangedForEvery::class)data class UserProfileFromEvery( @SetFrom("name", UserRegisteredForEvery::class) @SetFrom("newName", UserNameChangedForEvery::class) val name: String = "",
@SetFrom("email", UserRegisteredForEvery::class) @SetFrom("newEmail", UserEmailChangedForEvery::class) val email: String = "",
@FromEvery(contextProperty = "occurred") val lastUpdated: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.projections.FromEvent;import io.cratis.chronicle.projections.FromEvery;import io.cratis.chronicle.projections.SetFrom;import io.cratis.chronicle.readModels.ReadModel;
@EventTyperecord UserRegisteredForEvery(String name, String email) {}
@EventTyperecord UserNameChangedForEvery(String newName) {}
@EventTyperecord UserEmailChangedForEvery(String newEmail) {}
@ReadModel@FromEvent(eventType = UserRegisteredForEvery.class)@FromEvent(eventType = UserNameChangedForEvery.class)@FromEvent(eventType = UserEmailChangedForEvery.class)class UserProfileFromEvery { @SetFrom(propertyPath = "name", eventType = UserRegisteredForEvery.class) @SetFrom(propertyPath = "newName", eventType = UserNameChangedForEvery.class) public String name = "";
@SetFrom(propertyPath = "email", eventType = UserRegisteredForEvery.class) @SetFrom(propertyPath = "newEmail", eventType = UserEmailChangedForEvery.class) public String email = "";
@FromEvery(contextProperty = "occurred") public String lastUpdated = "";}defmodule MyApp.Events.UserRegisteredForEvery do use Cratis.Chronicle.Events.EventType, id: "user-registered-for-every-v1"
defstruct [:name, :email]end
defmodule MyApp.Events.UserNameChangedForEvery do use Cratis.Chronicle.Events.EventType, id: "user-name-changed-for-every-v1"
defstruct [:new_name]end
defmodule MyApp.Events.UserEmailChangedForEvery do use Cratis.Chronicle.Events.EventType, id: "user-email-changed-for-every-v1"
defstruct [:new_email]end
defmodule MyApp.ReadModels.UserProfileFromEvery do use Cratis.Chronicle.ReadModels.ReadModel
alias MyApp.Events.{UserEmailChangedForEvery, UserNameChangedForEvery, UserRegisteredForEvery}
defstruct [:id, :name, :email, :last_updated]
from UserRegisteredForEvery, set: [ id: :event_source_id, name: :name, email: :email ]
from UserNameChangedForEvery, set: [name: :new_name]
from UserEmailChangedForEvery, set: [email: :new_email]
from_every set: [last_updated: :occurred]endimport { eventType, fromEvent, fromEvery, setFrom } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()export class UserRegisteredForEvery { @field(String) readonly name: string; @field(String) readonly email: string;
constructor(name: string, email: string) { this.name = name; this.email = email; }}
@eventType()export class UserNameChangedForEvery { @field(String) readonly newName: string;
constructor(newName: string) { this.newName = newName; }}
@eventType()export class UserEmailChangedForEvery { @field(String) readonly newEmail: string;
constructor(newEmail: string) { this.newEmail = newEmail; }}
@fromEvent(UserRegisteredForEvery)@fromEvent(UserNameChangedForEvery)@fromEvent(UserEmailChangedForEvery)export class UserProfileFromEvery { @setFrom(UserRegisteredForEvery, 'name') @setFrom(UserNameChangedForEvery, 'newName') name = '';
@setFrom(UserRegisteredForEvery, 'email') @setFrom(UserEmailChangedForEvery, 'newEmail') email = '';
@fromEvery(undefined, 'occurred') lastUpdated = new Date();}When the name-change event is processed, the name mapping updates the business field and the every-event mapping records the event’s occurrence time in the last-modified field.
Declarative Equivalent
Section titled “Declarative Equivalent”If you move the mapping into a standalone projection, the intent stays the same. Both styles send an every-event definition to Chronicle:
using Cratis.Chronicle.Events;using Cratis.Chronicle.Keys;using Cratis.Chronicle.Projections;
[EventType]public record InventoryRegisteredDeclarativeForEvery(string ProductName);
[EventType]public record InventoryAdjustedDeclarativeForEvery(int Quantity);
public record InventoryStatusDeclarativeFromEvery( [property: Key] Guid Id, string ProductName, DateTimeOffset LastUpdated);
public class InventoryStatusDeclarativeProjection : IProjectionFor<InventoryStatusDeclarativeFromEvery>{ public void Define(IProjectionBuilderFor<InventoryStatusDeclarativeFromEvery> builder) => builder .From<InventoryRegisteredDeclarativeForEvery>() .From<InventoryAdjustedDeclarativeForEvery>() .FromEvery(_ => _ .Set(m => m.LastUpdated) .ToEventContextProperty(c => c.Occurred));}import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.projections.IProjectionBuilderForimport io.cratis.chronicle.projections.IProjectionFor
@EventTypedata class InventoryRegisteredDeclarativeForEvery(val productName: String)
@EventTypedata class InventoryAdjustedDeclarativeForEvery(val quantity: Int)
data class InventoryStatusDeclarativeFromEvery( val productName: String = "", val lastUpdated: String = "")
class InventoryStatusDeclarativeProjection : IProjectionFor<InventoryStatusDeclarativeFromEvery> { override fun define(builder: IProjectionBuilderFor<InventoryStatusDeclarativeFromEvery>) { builder .from(InventoryRegisteredDeclarativeForEvery::class) .from(InventoryAdjustedDeclarativeForEvery::class) .fromEvery { it -> it.set(InventoryStatusDeclarativeFromEvery::lastUpdated).toEventContextProperty("occurred") } }}import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.projections.IProjectionBuilderFor;import io.cratis.chronicle.projections.IProjectionFor;
@EventTyperecord InventoryRegisteredDeclarativeForEvery(String productName) {}
@EventTyperecord InventoryAdjustedDeclarativeForEvery(int quantity) {}
class InventoryStatusDeclarativeFromEvery { public String productName = ""; public String lastUpdated = "";}
class InventoryStatusDeclarativeProjection implements IProjectionFor<InventoryStatusDeclarativeFromEvery> { @Override public void define(IProjectionBuilderFor<InventoryStatusDeclarativeFromEvery> builder) { builder .from(InventoryRegisteredDeclarativeForEvery.class) .from(InventoryAdjustedDeclarativeForEvery.class) .fromEvery(every -> { every.set("lastUpdated").toEventContextProperty("occurred"); }); }}defmodule MyApp.Events.InventoryRegisteredDeclarativeForEvery do use Cratis.Chronicle.Events.EventType, id: "inventory-registered-declarative-for-every-v1"
defstruct [:product_name]end
defmodule MyApp.Events.InventoryAdjustedDeclarativeForEvery do use Cratis.Chronicle.Events.EventType, id: "inventory-adjusted-declarative-for-every-v1"
defstruct [:quantity]end
defmodule MyApp.ReadModels.InventoryStatusDeclarativeFromEvery do use Cratis.Chronicle.ReadModels.ReadModel
defstruct [:id, :product_name, :last_updated]end
defmodule MyApp.Projections.InventoryStatusDeclarativeProjection do use Cratis.Chronicle.Projections.Projection, model: MyApp.ReadModels.InventoryStatusDeclarativeFromEvery
alias MyApp.Events.{InventoryAdjustedDeclarativeForEvery, InventoryRegisteredDeclarativeForEvery}
from InventoryRegisteredDeclarativeForEvery, set: [ id: :event_source_id, product_name: :product_name ]
from InventoryAdjustedDeclarativeForEvery
from_every set: [last_updated: :occurred]endimport { eventType, IProjectionBuilderFor, IProjectionFor, projection } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()export class InventoryRegisteredDeclarativeForEvery { @field(String) readonly productName: string;
constructor(productName: string) { this.productName = productName; }}
@eventType()export class InventoryAdjustedDeclarativeForEvery { @field(Number) readonly quantity: number;
constructor(quantity: number) { this.quantity = quantity; }}
export class InventoryStatusDeclarativeFromEvery { productName = ''; lastUpdated = new Date();}
@projection('', InventoryStatusDeclarativeFromEvery)export class InventoryStatusDeclarativeProjection implements IProjectionFor<InventoryStatusDeclarativeFromEvery> { define(builder: IProjectionBuilderFor<InventoryStatusDeclarativeFromEvery>): void { builder .from(InventoryRegisteredDeclarativeForEvery) .from(InventoryAdjustedDeclarativeForEvery) .fromEvery(_ => _ .set(m => m.lastUpdated) .toEventContextProperty('occurred')); }}Use Cases
Section titled “Use Cases”| Use case | Typical source |
|---|---|
| Last modification time | Event context occurrence time |
| Last event sequence | Event context sequence number |
| Last operation id | Event context correlation id |
| Current status shared by all events | Event payload property |
Prefer context properties for audit metadata. Use payload properties only when the event contracts are intentionally consistent. If a property should update only for selected event types, use an event-specific mapping instead.
Child Events
Section titled “Child Events”In .NET, a root [FromEvery] includes events handled only by child projections, including nested child collections. Chronicle uses the child’s resolved parent key to update the containing parent’s audit fields. It does not create a root document keyed by the child identifier.
A child-only event advances a root [FromEvery] timestamp even without a root [FromEvent] for that event. In the declaration language, every includes child events by default; use exclude children to keep mappings local to their level.
Put [FromEvery] on a child’s own property when the child needs its own audit value. That mapping applies on the creating event and later events handled by the child. The same ownership rule applies to nested objects and [FromAll]: the object declaring the property owns the mapping. Parent fields are never copied into a newly added child.
For compatibility with clients that still put child mappings at the root, see Child and nested properties. A property declared on both root and child cannot be disambiguated until the client is upgraded.
Limitations
Section titled “Limitations”For child or nested every-mappings on join-only events, use the declarative alternative in model-bound limitations.
- Only one every-event mapping can target the same read model property.
- Payload-property mappings are skipped for events that do not carry the source property. A source property that is present with a null value still maps null.
- Model-bound
[FromEvery]has no child-exclusion option. Use a declarative projection withExcludeChildProjections()when you need to exclude child projections.