---
title: Projection With FromEvery
editUrl: https://github.com/Cratis/Chronicle/edit/main/Documentation/projections/declarative/from-every.mdx
description: Use an every-event mapping in a declarative projection when a read model property should update whenever any event handled by the projection is processed.…
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

Use an every-event mapping in a declarative projection when a read model property should update whenever any event handled by the projection is processed. This is most useful for audit metadata, event source identifiers, and other fields that should stay synchronized with the latest event.

The exact API name depends on the client. .NET and TypeScript expose `FromEvery` / `fromEvery`, while Elixir exposes `from_every`.

## Basic Usage

Map event context metadata when the read model needs to know when it was last touched.

<Tabs syncKey="chronicle-client">
<TabItem label="C#">

```csharp title="Declarative FromEvery"
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;

[EventType]
public record UserCreatedDeclarativeEvery(string Name, string Email);

[EventType]
public record UserEmailChangedDeclarativeEvery(string Email);

public record UserProfileDeclarativeEvery(
    string Name,
    string Email,
    DateTimeOffset LastUpdated);

public class UserProfileDeclarativeEveryProjection : IProjectionFor<UserProfileDeclarativeEvery>
{
    public void Define(IProjectionBuilderFor<UserProfileDeclarativeEvery> builder) => builder
        .From<UserCreatedDeclarativeEvery>()
        .From<UserEmailChangedDeclarativeEvery>()
        .FromEvery(_ => _
            .Set(m => m.LastUpdated)
            .ToEventContextProperty(c => c.Occurred));
}
```

[View C# snippet source on GitHub](https://github.com/Cratis/Chronicle/blob/main/Documentation/client-snippets/projections/declarative/from-every/basic.md)

</TabItem>
<TabItem label="Kotlin">

```kotlin title="Declarative FromEvery"
import io.cratis.chronicle.events.EventType
import io.cratis.chronicle.projections.IProjectionBuilderFor
import io.cratis.chronicle.projections.IProjectionFor

@EventType
data class UserCreatedDeclarativeEvery(val name: String, val email: String)

@EventType
data class UserEmailChangedDeclarativeEvery(val email: String)

data class UserProfileDeclarativeEvery(
    val name: String = "",
    val email: String = "",
    val lastUpdated: String = ""
)

class UserProfileDeclarativeEveryProjection : IProjectionFor<UserProfileDeclarativeEvery> {
    override fun define(builder: IProjectionBuilderFor<UserProfileDeclarativeEvery>) {
        builder
            .from(UserCreatedDeclarativeEvery::class)
            .from(UserEmailChangedDeclarativeEvery::class)
            .fromEvery { it.set(UserProfileDeclarativeEvery::lastUpdated).toEventContextProperty("occurred") }
    }
}
```

[View Kotlin snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets/projections/declarative/from-every/basic.md)

</TabItem>
<TabItem label="Java">

```java title="Declarative FromEvery"
import io.cratis.chronicle.events.EventType;
import io.cratis.chronicle.projections.IProjectionBuilderFor;
import io.cratis.chronicle.projections.IProjectionFor;

@EventType
record UserCreatedDeclarativeEvery(String name, String email) {}

@EventType
record UserEmailChangedDeclarativeEvery(String email) {}

class UserProfileDeclarativeEvery {
    public String name = "";
    public String email = "";
    public String lastUpdated = "";
}

class UserProfileDeclarativeEveryProjection implements IProjectionFor<UserProfileDeclarativeEvery> {
    @Override
    public void define(IProjectionBuilderFor<UserProfileDeclarativeEvery> builder) {
        builder
            .from(UserCreatedDeclarativeEvery.class)
            .from(UserEmailChangedDeclarativeEvery.class)
            .fromEvery(feb -> {
                feb.set("lastUpdated").toEventContextProperty("occurred");
            });
    }
}
```

[View Java snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets-java/projections/declarative/from-every/basic.md)

</TabItem>
<TabItem label="Elixir">

```elixir title="Declarative from_every"
defmodule MyApp.Events.UserCreatedDeclarativeEvery do
  use Chronicle.Events.EventType, id: "user-created-declarative-every-v1"

  defstruct [:name, :email]
end

defmodule MyApp.Events.UserEmailChangedDeclarativeEvery do
  use Chronicle.Events.EventType, id: "user-email-changed-declarative-every-v1"

  defstruct [:email]
end

defmodule MyApp.ReadModels.UserProfileDeclarativeEvery do
  use Chronicle.ReadModels.ReadModel

  defstruct [:name, :email, :last_updated]
end

defmodule MyApp.Projections.UserProfileDeclarativeEveryProjection do
  use Chronicle.Projections.Projection, model: MyApp.ReadModels.UserProfileDeclarativeEvery

  alias MyApp.Events.{UserCreatedDeclarativeEvery, UserEmailChangedDeclarativeEvery}

  from UserCreatedDeclarativeEvery,
    set: [
      name: :name,
      email: :email
    ]

  from UserEmailChangedDeclarativeEvery,
    set: [email: :email]

  from_every set: [last_updated: :occurred]
end
```

[View Elixir snippet source on GitHub](https://github.com/Cratis/Chronicle.Elixir/blob/main/Documentation/client-snippets/projections/declarative/from-every/basic.md)

</TabItem>
<TabItem label="TypeScript">

```typescript title="Declarative fromEvery"
import { eventType, IProjectionBuilderFor, IProjectionFor, projection } from '@cratis/chronicle';
import { field } from '@cratis/fundamentals';

@eventType()
export class UserCreatedDeclarativeEvery {
    @field(String) readonly name: string;
    @field(String) readonly email: string;

    constructor(name: string, email: string) {
        this.name = name;
        this.email = email;
    }
}

@eventType()
export class UserEmailChangedDeclarativeEvery {
    @field(String) readonly email: string;

    constructor(email: string) {
        this.email = email;
    }
}

export class UserProfileDeclarativeEvery {
    name = '';
    email = '';
    lastUpdated = new Date();
}

@projection('', UserProfileDeclarativeEvery)
export class UserProfileDeclarativeEveryProjection implements IProjectionFor<UserProfileDeclarativeEvery> {
    define(builder: IProjectionBuilderFor<UserProfileDeclarativeEvery>): void {
        builder
            .from(UserCreatedDeclarativeEvery)
            .from(UserEmailChangedDeclarativeEvery)
            .fromEvery(_ => _
                .set(m => m.lastUpdated)
                .toEventContextProperty('occurred'));
    }
}
```

[View TypeScript snippet source on GitHub](https://github.com/Cratis/Chronicle.TypeScript/blob/main/Documentation/client-snippets/projections/declarative/from-every/basic.md)

</TabItem>
</Tabs>

## Event Context Fields

Every-event mappings can map more than one context field.

<Tabs syncKey="chronicle-client">
<TabItem label="C#">

```csharp title="Map multiple context fields"
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;

[EventType]
public record AccountTouchedDeclarativeEvery(string Reason);

public record AccountAuditDeclarativeEvery(
    DateTimeOffset LastUpdated,
    EventSequenceNumber LastEventSequence,
    string LastCorrelationId);

public class AccountAuditDeclarativeEveryProjection : IProjectionFor<AccountAuditDeclarativeEvery>
{
    public void Define(IProjectionBuilderFor<AccountAuditDeclarativeEvery> builder) => builder
        .From<AccountTouchedDeclarativeEvery>()
        .FromEvery(_ => _
            .Set(m => m.LastUpdated).ToEventContextProperty(c => c.Occurred)
            .Set(m => m.LastEventSequence).ToEventContextProperty(c => c.SequenceNumber)
            .Set(m => m.LastCorrelationId).ToEventContextProperty(c => c.CorrelationId));
}
```

[View C# snippet source on GitHub](https://github.com/Cratis/Chronicle/blob/main/Documentation/client-snippets/projections/declarative/from-every/context-fields.md)

</TabItem>
<TabItem label="Kotlin">

```kotlin title="Map multiple context fields"
import io.cratis.chronicle.events.EventType
import io.cratis.chronicle.projections.IProjectionBuilderFor
import io.cratis.chronicle.projections.IProjectionFor

@EventType
data class AccountTouchedDeclarativeEvery(val reason: String)

data class AccountAuditDeclarativeEvery(
    val lastUpdated: String = "",
    val lastEventSequence: String = "",
    val lastCorrelationId: String = ""
)

class AccountAuditDeclarativeEveryProjection : IProjectionFor<AccountAuditDeclarativeEvery> {
    override fun define(builder: IProjectionBuilderFor<AccountAuditDeclarativeEvery>) {
        builder
            .from(AccountTouchedDeclarativeEvery::class)
            .fromEvery {
                it.set(AccountAuditDeclarativeEvery::lastUpdated).toEventContextProperty("occurred")
                it.set(AccountAuditDeclarativeEvery::lastEventSequence).toEventContextProperty("sequenceNumber")
                it.set(AccountAuditDeclarativeEvery::lastCorrelationId).toEventContextProperty("correlationId")
            }
    }
}
```

[View Kotlin snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets/projections/declarative/from-every/context-fields.md)

</TabItem>
<TabItem label="Java">

```java title="Map multiple context fields"
import io.cratis.chronicle.events.EventType;
import io.cratis.chronicle.projections.IProjectionBuilderFor;
import io.cratis.chronicle.projections.IProjectionFor;

@EventType
record AccountTouchedDeclarativeEvery(String reason) {}

class AccountAuditDeclarativeEvery {
    public String lastUpdated = "";
    public String lastEventSequence = "";
    public String lastCorrelationId = "";
}

class AccountAuditDeclarativeEveryProjection implements IProjectionFor<AccountAuditDeclarativeEvery> {
    @Override
    public void define(IProjectionBuilderFor<AccountAuditDeclarativeEvery> builder) {
        builder
            .from(AccountTouchedDeclarativeEvery.class)
            .fromEvery(feb -> {
                feb.set("lastUpdated").toEventContextProperty("occurred");
                feb.set("lastEventSequence").toEventContextProperty("sequenceNumber");
                feb.set("lastCorrelationId").toEventContextProperty("correlationId");
            });
    }
}
```

[View Java snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets-java/projections/declarative/from-every/context-fields.md)

</TabItem>
<TabItem label="Elixir">

```elixir title="Map multiple context fields"
defmodule MyApp.Events.AccountTouchedDeclarativeEvery do
  use Chronicle.Events.EventType, id: "account-touched-declarative-every-v1"

  defstruct [:reason]
end

defmodule MyApp.ReadModels.AccountAuditDeclarativeEvery do
  use Chronicle.ReadModels.ReadModel

  defstruct [:last_updated, :last_event_sequence, :last_correlation_id]
end

defmodule MyApp.Projections.AccountAuditDeclarativeEveryProjection do
  use Chronicle.Projections.Projection, model: MyApp.ReadModels.AccountAuditDeclarativeEvery

  alias MyApp.Events.AccountTouchedDeclarativeEvery

  from AccountTouchedDeclarativeEvery

  from_every set: [
    last_updated: :occurred,
    last_event_sequence: "$context.sequenceNumber",
    last_correlation_id: "$context.correlationId"
  ]
end
```

[View Elixir snippet source on GitHub](https://github.com/Cratis/Chronicle.Elixir/blob/main/Documentation/client-snippets/projections/declarative/from-every/context-fields.md)

</TabItem>
<TabItem label="TypeScript">

```typescript title="Map multiple context fields"
import { eventType, IProjectionBuilderFor, IProjectionFor, projection } from '@cratis/chronicle';
import { field } from '@cratis/fundamentals';

@eventType()
export class AccountTouchedDeclarativeEvery {
    @field(String) readonly reason: string;

    constructor(reason: string) {
        this.reason = reason;
    }
}

export class AccountAuditDeclarativeEvery {
    lastUpdated = new Date();
    lastEventSequence = 0n;
    lastCorrelationId = '';
}

@projection('', AccountAuditDeclarativeEvery)
export class AccountAuditDeclarativeEveryProjection implements IProjectionFor<AccountAuditDeclarativeEvery> {
    define(builder: IProjectionBuilderFor<AccountAuditDeclarativeEvery>): void {
        builder
            .from(AccountTouchedDeclarativeEvery)
            .fromEvery(_ => _
                .set(m => m.lastUpdated).toEventContextProperty('occurred')
                .set(m => m.lastEventSequence).toEventContextProperty('sequenceNumber')
                .set(m => m.lastCorrelationId).toEventContextProperty('correlationId'));
    }
}
```

[View TypeScript snippet source on GitHub](https://github.com/Cratis/Chronicle.TypeScript/blob/main/Documentation/client-snippets/projections/declarative/from-every/context-fields.md)

</TabItem>
</Tabs>

## Event Source Id

Map the event source id when the read model's primary identifier is not otherwise populated from each event payload.

<Tabs syncKey="chronicle-client">
<TabItem label="C#">

```csharp title="Map the event source id"
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;

[EventType]
public record AccountOpenedDeclarativeEvery(string OwnerName);

public record AccountSummaryDeclarativeEvery(
    string AccountId,
    string OwnerName);

public class AccountSummaryDeclarativeEveryProjection : IProjectionFor<AccountSummaryDeclarativeEvery>
{
    public void Define(IProjectionBuilderFor<AccountSummaryDeclarativeEvery> builder) => builder
        .From<AccountOpenedDeclarativeEvery>()
        .FromEvery(_ => _
            .Set(m => m.AccountId)
            .ToEventSourceId());
}
```

[View C# snippet source on GitHub](https://github.com/Cratis/Chronicle/blob/main/Documentation/client-snippets/projections/declarative/from-every/event-source-id.md)

</TabItem>
<TabItem label="Kotlin">

```kotlin title="Map the event source id"
import io.cratis.chronicle.events.EventType
import io.cratis.chronicle.projections.IProjectionBuilderFor
import io.cratis.chronicle.projections.IProjectionFor

@EventType
data class AccountOpenedDeclarativeEvery(val ownerName: String)

data class AccountSummaryDeclarativeEvery(
    val accountId: String = "",
    val ownerName: String = ""
)

class AccountSummaryDeclarativeEveryProjection : IProjectionFor<AccountSummaryDeclarativeEvery> {
    override fun define(builder: IProjectionBuilderFor<AccountSummaryDeclarativeEvery>) {
        builder
            .from(AccountOpenedDeclarativeEvery::class)
            .fromEvery { it.set(AccountSummaryDeclarativeEvery::accountId).toEventSourceId() }
    }
}
```

[View Kotlin snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets/projections/declarative/from-every/event-source-id.md)

</TabItem>
<TabItem label="Java">

```java title="Map the event source id"
import io.cratis.chronicle.events.EventType;
import io.cratis.chronicle.projections.IProjectionBuilderFor;
import io.cratis.chronicle.projections.IProjectionFor;

@EventType
record AccountOpenedDeclarativeEvery(String ownerName) {}

class AccountSummaryDeclarativeEvery {
    public String accountId = "";
    public String ownerName = "";
}

class AccountSummaryDeclarativeEveryProjection implements IProjectionFor<AccountSummaryDeclarativeEvery> {
    @Override
    public void define(IProjectionBuilderFor<AccountSummaryDeclarativeEvery> builder) {
        builder
            .from(AccountOpenedDeclarativeEvery.class)
            .fromEvery(feb -> {
                feb.set("accountId").toEventSourceId();
            });
    }
}
```

[View Java snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets-java/projections/declarative/from-every/event-source-id.md)

</TabItem>
<TabItem label="Elixir">

```elixir title="Map the event source id"
defmodule MyApp.Events.AccountOpenedDeclarativeEvery do
  use Chronicle.Events.EventType, id: "account-opened-declarative-every-v1"

  defstruct [:owner_name]
end

defmodule MyApp.ReadModels.AccountSummaryDeclarativeEvery do
  use Chronicle.ReadModels.ReadModel

  defstruct [:account_id, :owner_name]
end

defmodule MyApp.Projections.AccountSummaryDeclarativeEveryProjection do
  use Chronicle.Projections.Projection, model: MyApp.ReadModels.AccountSummaryDeclarativeEvery

  alias MyApp.Events.AccountOpenedDeclarativeEvery

  from AccountOpenedDeclarativeEvery,
    set: [owner_name: :owner_name]

  from_every set: [account_id: :event_source_id]
end
```

[View Elixir snippet source on GitHub](https://github.com/Cratis/Chronicle.Elixir/blob/main/Documentation/client-snippets/projections/declarative/from-every/event-source-id.md)

</TabItem>
<TabItem label="TypeScript">

```typescript title="Map the event source id"
import { eventType, IProjectionBuilderFor, IProjectionFor, projection } from '@cratis/chronicle';
import { field } from '@cratis/fundamentals';

@eventType()
export class AccountOpenedDeclarativeEvery {
    @field(String) readonly ownerName: string;

    constructor(ownerName: string) {
        this.ownerName = ownerName;
    }
}

export class AccountSummaryDeclarativeEvery {
    accountId = '';
    ownerName = '';
}

@projection('', AccountSummaryDeclarativeEvery)
export class AccountSummaryDeclarativeEveryProjection implements IProjectionFor<AccountSummaryDeclarativeEvery> {
    define(builder: IProjectionBuilderFor<AccountSummaryDeclarativeEvery>): void {
        builder
            .from(AccountOpenedDeclarativeEvery)
            .fromEvery(_ => _
                .set(m => m.accountId)
                .toEventSourceId());
    }
}
```

[View TypeScript snippet source on GitHub](https://github.com/Cratis/Chronicle.TypeScript/blob/main/Documentation/client-snippets/projections/declarative/from-every/event-source-id.md)

</TabItem>
</Tabs>

## Child Projection Inclusion

The kernel now honors the child-inclusion flag. In .NET, `FromEvery` includes events handled only by child projections by default, including nested child collections. These mappings update the containing parent using the child's resolved parent key, not a new root keyed by the child identifier. Existing fluent projections therefore start updating parent audit fields on child-only events.

Call `ExcludeChildProjections()` to keep every-event mappings local to the level where they are declared. That level's own `from` and `join` events still apply the mappings. In the declaration language, `every` also includes child events by default; add `exclude children` to opt out.

<Tabs syncKey="chronicle-client">
<TabItem label="C#">

```csharp title="Exclude child projection events"
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;

[EventType]
public record OrderCreatedDeclarativeEveryExclude(string OrderNumber);

public record OrderAuditDeclarativeEveryExclude(
    string OrderNumber,
    DateTimeOffset LastUpdated);

public class OrderAuditDeclarativeEveryExcludeProjection : IProjectionFor<OrderAuditDeclarativeEveryExclude>
{
    public void Define(IProjectionBuilderFor<OrderAuditDeclarativeEveryExclude> builder) => builder
        .From<OrderCreatedDeclarativeEveryExclude>()
        .FromEvery(_ => _
            .Set(m => m.LastUpdated)
            .ToEventContextProperty(c => c.Occurred)
            .ExcludeChildProjections());
}
```

[View C# snippet source on GitHub](https://github.com/Cratis/Chronicle/blob/main/Documentation/client-snippets/projections/declarative/from-every/exclude-children.md)

</TabItem>
<TabItem label="Kotlin">

```text
Kotlin does not support this workflow yet.
```

[View Kotlin snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets/projections/declarative/from-every/exclude-children.md)

</TabItem>
<TabItem label="Java">

```text
Java does not support this workflow yet.
```

[View Java snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets-java/projections/declarative/from-every/exclude-children.md)

</TabItem>
<TabItem label="Elixir">

```elixir title="Exclude child projection events"
defmodule MyApp.Events.OrderCreatedDeclarativeEveryExclude do
  use Chronicle.Events.EventType, id: "order-created-declarative-every-exclude-v1"

  defstruct [:order_number]
end

defmodule MyApp.ReadModels.OrderAuditDeclarativeEveryExclude do
  use Chronicle.ReadModels.ReadModel

  defstruct [:order_number, :last_updated]
end

defmodule MyApp.Projections.OrderAuditDeclarativeEveryExcludeProjection do
  use Chronicle.Projections.Projection, model: MyApp.ReadModels.OrderAuditDeclarativeEveryExclude

  alias MyApp.Events.OrderCreatedDeclarativeEveryExclude

  from OrderCreatedDeclarativeEveryExclude

  from_every set: [last_updated: :occurred], include_children: false
end
```

[View Elixir snippet source on GitHub](https://github.com/Cratis/Chronicle.Elixir/blob/main/Documentation/client-snippets/projections/declarative/from-every/exclude-children.md)

</TabItem>
<TabItem label="TypeScript">

```typescript title="Exclude child projection events"
import { eventType, IProjectionBuilderFor, IProjectionFor, projection } from '@cratis/chronicle';
import { field } from '@cratis/fundamentals';

@eventType()
export class OrderCreatedDeclarativeEveryExclude {
    @field(String) readonly orderNumber: string;

    constructor(orderNumber: string) {
        this.orderNumber = orderNumber;
    }
}

export class OrderAuditDeclarativeEveryExclude {
    orderNumber = '';
    lastUpdated = new Date();
}

@projection('', OrderAuditDeclarativeEveryExclude)
export class OrderAuditDeclarativeEveryExcludeProjection implements IProjectionFor<OrderAuditDeclarativeEveryExclude> {
    define(builder: IProjectionBuilderFor<OrderAuditDeclarativeEveryExclude>): void {
        builder
            .from(OrderCreatedDeclarativeEveryExclude)
            .fromEvery(_ => _
                .set(m => m.lastUpdated)
                .toEventContextProperty('occurred')
                .excludeChildProjections());
    }
}
```

[View TypeScript snippet source on GitHub](https://github.com/Cratis/Chronicle.TypeScript/blob/main/Documentation/client-snippets/projections/declarative/from-every/exclude-children.md)

</TabItem>
</Tabs>

Use a root `FromAll` mapping only when the parent must also observe unrelated event types in the sequence. Its child-inclusion flag is true, so child-only events update their containing parent too. Use `FromEvery` for audit metadata that should follow just the projection's handled events.

<Tabs syncKey="chronicle-client">
<TabItem label="C#">

```csharp title="Include child projection events"
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;

[EventType]
public record OrderCreatedDeclarativeEveryChildren(string OrderNumber);

[EventType]
public record ItemAddedDeclarativeEveryChildren(string OrderId, string ProductId, string ProductName, int Quantity);

[EventType]
public record ItemQuantityChangedDeclarativeEveryChildren(string OrderId, string ProductId, int Quantity);

public record OrderDeclarativeEveryChildren(
    string OrderNumber,
    DateTimeOffset LastModified,
    IEnumerable<OrderItemDeclarativeEveryChildren> Items);

public record OrderItemDeclarativeEveryChildren(
    string ProductId,
    string ProductName,
    int Quantity);

public class OrderDeclarativeEveryChildrenProjection : IProjectionFor<OrderDeclarativeEveryChildren>
{
    public void Define(IProjectionBuilderFor<OrderDeclarativeEveryChildren> builder) => builder
        .From<OrderCreatedDeclarativeEveryChildren>()
        .FromEvery(_ => _
            .Set(m => m.LastModified)
            .ToEventContextProperty(c => c.Occurred))
        .Children(m => m.Items, children => children
            .IdentifiedBy(m => m.ProductId)
            .From<ItemAddedDeclarativeEveryChildren>(_ => _
                .UsingKey(e => e.ProductId)
                .UsingParentKey(e => e.OrderId))
            .From<ItemQuantityChangedDeclarativeEveryChildren>(_ => _
                .UsingKey(e => e.ProductId)
                .UsingParentKey(e => e.OrderId)));
}
```

[View C# snippet source on GitHub](https://github.com/Cratis/Chronicle/blob/main/Documentation/client-snippets/projections/declarative/from-every/with-children.md)

</TabItem>
<TabItem label="Kotlin">

```kotlin title="Include child projection events"
import io.cratis.chronicle.events.EventType
import io.cratis.chronicle.projections.IProjectionBuilderFor
import io.cratis.chronicle.projections.IProjectionFor
import java.time.Instant

@EventType
data class OrderCreatedDeclarativeEveryChildren(val orderNumber: String)

@EventType
data class ItemAddedDeclarativeEveryChildren(
    val orderId: String,
    val productId: String,
    val productName: String,
    val quantity: Int
)

@EventType
data class ItemQuantityChangedDeclarativeEveryChildren(
    val orderId: String,
    val productId: String,
    val quantity: Int
)

data class OrderDeclarativeEveryChildren(
    val orderNumber: String = "",
    val lastModified: Instant = Instant.EPOCH,
    val items: List<OrderItemDeclarativeEveryChildren> = emptyList()
)

data class OrderItemDeclarativeEveryChildren(
    val productId: String = "",
    val productName: String = "",
    val quantity: Int = 0
)

class OrderDeclarativeEveryChildrenProjection : IProjectionFor<OrderDeclarativeEveryChildren> {
    override fun define(builder: IProjectionBuilderFor<OrderDeclarativeEveryChildren>) {
        builder
            .from(OrderCreatedDeclarativeEveryChildren::class)
            .fromEvery { it.set(OrderDeclarativeEveryChildren::lastModified).toEventContextProperty("occurred") }
            .children(OrderDeclarativeEveryChildren::items, OrderItemDeclarativeEveryChildren::class) { children ->
                children
                    .identifiedBy("productId")
                    .from(ItemAddedDeclarativeEveryChildren::class) {
                        it.usingKey("productId").usingParentKey("orderId")
                    }
                    .from(ItemQuantityChangedDeclarativeEveryChildren::class) {
                        it.usingKey("productId").usingParentKey("orderId")
                    }
            }
    }
}
```

[View Kotlin snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets/projections/declarative/from-every/with-children.md)

</TabItem>
<TabItem label="Java">

```java title="Include child projection events"
import io.cratis.chronicle.events.EventType;
import io.cratis.chronicle.projections.IProjectionBuilderFor;
import io.cratis.chronicle.projections.IProjectionFor;

import java.time.Instant;
import java.util.List;

@EventType
record OrderCreatedDeclarativeEveryChildren(String orderNumber) {}

@EventType
record ItemAddedDeclarativeEveryChildren(String orderId, String productId, String productName, int quantity) {}

@EventType
record ItemQuantityChangedDeclarativeEveryChildren(String orderId, String productId, int quantity) {}

class OrderDeclarativeEveryChildren {
    public String orderNumber = "";
    public Instant lastModified = Instant.EPOCH;
    public List<OrderItemDeclarativeEveryChildren> items = List.of();
}

record OrderItemDeclarativeEveryChildren(String productId, String productName, int quantity) {}

class OrderDeclarativeEveryChildrenProjection implements IProjectionFor<OrderDeclarativeEveryChildren> {
    @Override
    public void define(IProjectionBuilderFor<OrderDeclarativeEveryChildren> builder) {
        builder
            .from(OrderCreatedDeclarativeEveryChildren.class)
            .fromEvery(feb -> {
                feb.set("lastModified").toEventContextProperty("occurred");
            })
            .children("items", OrderItemDeclarativeEveryChildren.class, children -> {
                children
                    .identifiedBy("productId")
                    .from(ItemAddedDeclarativeEveryChildren.class, fb -> {
                        fb.usingKey("productId");
                        fb.usingParentKey("orderId");
                    })
                    .from(ItemQuantityChangedDeclarativeEveryChildren.class, fb -> {
                        fb.usingKey("productId");
                        fb.usingParentKey("orderId");
                    });
            });
    }
}
```

[View Java snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets-java/projections/declarative/from-every/with-children.md)

</TabItem>
<TabItem label="Elixir">

```text
Elixir does not support this workflow yet.
```

[View Elixir snippet source on GitHub](https://github.com/Cratis/Chronicle.Elixir/blob/main/Documentation/client-snippets/projections/declarative/from-every/with-children.md)

</TabItem>
<TabItem label="TypeScript">

```typescript
import { eventType, IProjectionBuilderFor, IProjectionFor, projection } from '@cratis/chronicle';
import { field } from '@cratis/fundamentals';

@eventType()
class OrderCreatedDeclarativeEveryChildren {
    @field(String) readonly orderNumber: string;

    constructor(orderNumber: string) {
        this.orderNumber = orderNumber;
    }
}

@eventType()
class ItemAddedDeclarativeEveryChildren {
    @field(String) readonly orderId: string;
    @field(String) readonly productId: string;
    @field(String) readonly productName: string;
    @field(Number) readonly quantity: number;

    constructor(orderId: string, productId: string, productName: string, quantity: number) {
        this.orderId = orderId;
        this.productId = productId;
        this.productName = productName;
        this.quantity = quantity;
    }
}

@eventType()
class ItemQuantityChangedDeclarativeEveryChildren {
    @field(String) readonly orderId: string;
    @field(String) readonly productId: string;
    @field(Number) readonly quantity: number;

    constructor(orderId: string, productId: string, quantity: number) {
        this.orderId = orderId;
        this.productId = productId;
        this.quantity = quantity;
    }
}

class OrderItemDeclarativeEveryChildren {
    productId = '';
    productName = '';
    quantity = 0;
}

class OrderDeclarativeEveryChildren {
    orderNumber = '';
    lastModified = new Date();
    items: OrderItemDeclarativeEveryChildren[] = [];
}

@projection()
class OrderDeclarativeEveryChildrenProjection implements IProjectionFor<OrderDeclarativeEveryChildren> {
    define(builder: IProjectionBuilderFor<OrderDeclarativeEveryChildren>): void {
        builder
            .from(OrderCreatedDeclarativeEveryChildren)
            .fromEvery(_ => _
                .set(m => m.lastModified)
                .toEventContextProperty('occurred'))
            .children<OrderItemDeclarativeEveryChildren>(m => m.items, children => children
                .identifiedBy(m => m.productId)
                .from(ItemAddedDeclarativeEveryChildren, _ => _
                    .usingKey(e => e.productId)
                    .usingParentKey(e => e.orderId))
                .from(ItemQuantityChangedDeclarativeEveryChildren, _ => _
                    .usingKey(e => e.productId)
                    .usingParentKey(e => e.orderId)));
    }
}
```

[View TypeScript snippet source on GitHub](https://github.com/Cratis/Chronicle.TypeScript/blob/main/Documentation/client-snippets/projections/declarative/from-every/with-children.md)

</TabItem>
</Tabs>

## Multiple Declarations

Clients that support multiple every-event declarations merge the property mappings into one projection definition.

:::note[Elixir]
Elixir's `from_every/1` macro accumulates multiple declarations, but the registration coordinator currently only sends the first one to the kernel — a second `from_every` call is silently dropped. Use a single `from_every` call with all of the property mappings combined instead.
:::

<Tabs syncKey="chronicle-client">
<TabItem label="C#">

```csharp title="Multiple FromEvery declarations"
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;

[EventType]
public record UserChangedDeclarativeEveryMultiple(string Name);

public record UserAuditDeclarativeEveryMultiple(
    string Name,
    DateTimeOffset LastUpdated,
    string ModifiedBy);

public class UserAuditDeclarativeEveryMultipleProjection : IProjectionFor<UserAuditDeclarativeEveryMultiple>
{
    public void Define(IProjectionBuilderFor<UserAuditDeclarativeEveryMultiple> builder) => builder
        .From<UserChangedDeclarativeEveryMultiple>()
        .FromEvery(_ => _
            .Set(m => m.LastUpdated)
            .ToEventContextProperty(c => c.Occurred))
        .FromEvery(_ => _
            .Set(m => m.ModifiedBy)
            .ToEventContextProperty(c => c.CausedBy));
}
```

[View C# snippet source on GitHub](https://github.com/Cratis/Chronicle/blob/main/Documentation/client-snippets/projections/declarative/from-every/multiple-declarations.md)

</TabItem>
<TabItem label="Kotlin">

```kotlin title="Multiple FromEvery declarations"
import io.cratis.chronicle.events.EventType
import io.cratis.chronicle.projections.IProjectionBuilderFor
import io.cratis.chronicle.projections.IProjectionFor

@EventType
data class UserChangedDeclarativeEveryMultiple(val name: String)

data class UserAuditDeclarativeEveryMultiple(
    val name: String = "",
    val lastUpdated: String = "",
    val modifiedBy: String = ""
)

class UserAuditDeclarativeEveryMultipleProjection : IProjectionFor<UserAuditDeclarativeEveryMultiple> {
    override fun define(builder: IProjectionBuilderFor<UserAuditDeclarativeEveryMultiple>) {
        builder
            .from(UserChangedDeclarativeEveryMultiple::class)
            .fromEvery { it.set(UserAuditDeclarativeEveryMultiple::lastUpdated).toEventContextProperty("occurred") }
            .fromEvery { it.set(UserAuditDeclarativeEveryMultiple::modifiedBy).toEventContextProperty("causedBy") }
    }
}
```

[View Kotlin snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets/projections/declarative/from-every/multiple-declarations.md)

</TabItem>
<TabItem label="Java">

```java title="Multiple FromEvery declarations"
import io.cratis.chronicle.events.EventType;
import io.cratis.chronicle.projections.IProjectionBuilderFor;
import io.cratis.chronicle.projections.IProjectionFor;

@EventType
record UserChangedDeclarativeEveryMultiple(String name) {}

class UserAuditDeclarativeEveryMultiple {
    public String name = "";
    public String lastUpdated = "";
    public String modifiedBy = "";
}

class UserAuditDeclarativeEveryMultipleProjection implements IProjectionFor<UserAuditDeclarativeEveryMultiple> {
    @Override
    public void define(IProjectionBuilderFor<UserAuditDeclarativeEveryMultiple> builder) {
        builder
            .from(UserChangedDeclarativeEveryMultiple.class)
            .fromEvery(feb -> {
                feb.set("lastUpdated").toEventContextProperty("occurred");
            })
            .fromEvery(feb -> {
                feb.set("modifiedBy").toEventContextProperty("causedBy");
            });
    }
}
```

[View Java snippet source on GitHub](https://github.com/Cratis/Chronicle.Kotlin/blob/main/Documentation/client-snippets-java/projections/declarative/from-every/multiple-declarations.md)

</TabItem>
<TabItem label="Elixir">

```elixir
defmodule MyApp.Events.UserChangedEveryMultiple do
  use Chronicle.Events.EventType, id: "user-changed-every-multiple"

  defstruct [:name]
end

defmodule MyApp.ReadModels.UserAuditEveryMultiple do
  use Chronicle.ReadModels.ReadModel

  defstruct id: nil, name: nil, last_updated: nil, subject_id: nil

  from MyApp.Events.UserChangedEveryMultiple,
    set: [name: :name]

  # Every declaration contributes - they are merged, not replaced.
  from_every(set: [last_updated: :occurred])
  from_every(set: [subject_id: :event_source_id])
end
```

[View Elixir snippet source on GitHub](https://github.com/Cratis/Chronicle.Elixir/blob/main/Documentation/client-snippets/projections/declarative/from-every/multiple-declarations.md)

</TabItem>
<TabItem label="TypeScript">

```typescript title="Multiple fromEvery declarations"
import { eventType, IProjectionBuilderFor, IProjectionFor, projection } from '@cratis/chronicle';
import { field } from '@cratis/fundamentals';

@eventType()
export class UserChangedDeclarativeEveryMultiple {
    @field(String) readonly name: string;

    constructor(name: string) {
        this.name = name;
    }
}

export class UserAuditDeclarativeEveryMultiple {
    name = '';
    lastUpdated = new Date();
    modifiedBy = '';
}

@projection('', UserAuditDeclarativeEveryMultiple)
export class UserAuditDeclarativeEveryMultipleProjection implements IProjectionFor<UserAuditDeclarativeEveryMultiple> {
    define(builder: IProjectionBuilderFor<UserAuditDeclarativeEveryMultiple>): void {
        builder
            .from(UserChangedDeclarativeEveryMultiple)
            .fromEvery(_ => _
                .set(m => m.lastUpdated)
                .toEventContextProperty('occurred'))
            .fromEvery(_ => _
                .set(m => m.modifiedBy)
                .toEventContextProperty('causedBy'));
    }
}
```

[View TypeScript snippet source on GitHub](https://github.com/Cratis/Chronicle.TypeScript/blob/main/Documentation/client-snippets/projections/declarative/from-every/multiple-declarations.md)

</TabItem>
</Tabs>

## Common Use Cases

| Use case | Typical source |
| --- | --- |
| Audit timestamp | Event context occurrence time |
| Event sequencing | Event context sequence number |
| Correlation tracking | Event context correlation id |
| Event source identification | Event source id |

Use event-specific mappings when the property should update only for selected event types.
