Skip to content

CHR0003: Model bound projection attribute must reference event type with [EventType] attribute

Model bound projection attributes (such as FromEventAttribute<TEvent>, RemovedWithAttribute<TEvent>, etc.) must reference types that are marked with the [EventType] attribute.

Error

using Cratis.Chronicle.Projections.ModelBound;
// Missing [EventType] attribute
public record Chr0003ProductAdded(Guid ProductId, string Name, decimal Price);
// CHR0003: Type 'Chr0003ProductAdded' must be marked with [EventType] attribute
[FromEvent<Chr0003ProductAdded>]
public class Chr0003ProductReadModel
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }
}
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections.ModelBound;
[EventType]
public record Chr0003ProductAddedFixed(Guid ProductId, string Name, decimal Price);
// Now valid
[FromEvent<Chr0003ProductAddedFixed>]
public class Chr0003ProductReadModelFixed
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }
}

This rule applies to the following model bound projection attributes:

  • FromEventAttribute<TEvent>
  • RemovedWithAttribute<TEvent>
  • RemovedWithJoinAttribute<TEvent>
  • JoinAttribute<TEvent>
  • ChildrenFromAttribute<TEvent>
  • FromEveryAttribute<TEvent>

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

Model bound projections use attributes to define how events map to read models. These attributes must reference valid event types to ensure:

  • Proper event-to-model mapping
  • Correct projection materialization
  • Type-safe projection definitions
  • Accurate event handling
  • CHR0001: Event sequence append operations
  • CHR0002: Declarative projection event types