Skip to content

CHR0002: Declarative projection event type must have [EventType] attribute

Generic type arguments in declarative projections that reference event types must be marked with the [EventType] attribute.

Error

using Cratis.Chronicle.Projections;
// Missing [EventType] attribute
public record Chr0002OrderCreated(Guid OrderId, decimal Amount);
public class Chr0002OrderReadModel
{
public Guid Id { get; set; }
public decimal Amount { get; set; }
}
public class Chr0002OrderProjection : IProjectionFor<Chr0002OrderReadModel>
{
public void Define(IProjectionBuilderFor<Chr0002OrderReadModel> builder) =>
// CHR0002: Type 'Chr0002OrderCreated' must be marked with [EventType] attribute
builder.From<Chr0002OrderCreated>(_ => _
.Set(m => m.Id).To(e => e.OrderId)
.Set(m => m.Amount).To(e => e.Amount));
}
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;
[EventType]
public record Chr0002OrderCreatedFixed(Guid OrderId, decimal Amount);
public class Chr0002OrderReadModelFixed
{
public Guid Id { get; set; }
public decimal Amount { get; set; }
}
public class Chr0002OrderProjectionFixed : IProjectionFor<Chr0002OrderReadModelFixed>
{
public void Define(IProjectionBuilderFor<Chr0002OrderReadModelFixed> builder) =>
// Now valid
builder.From<Chr0002OrderCreatedFixed>(_ => _
.Set(m => m.Id).To(e => e.OrderId)
.Set(m => m.Amount).To(e => e.Amount));
}

The analyzer provides a code fix that automatically adds the [EventType] attribute to the referenced type.

Declarative projections define how events are projected into read models. All event types used in these projections must be properly identified to ensure:

  • Correct event routing and handling
  • Proper schema tracking
  • Type-safe projection definitions
  • CHR0001: Event sequence append operations
  • CHR0003: Model bound projection attributes