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

// Missing [EventType] attribute
public record ProductAdded(Guid ProductId, string Name, decimal Price);
// CHR0003: Type 'ProductAdded' must be marked with [EventType] attribute
[FromEvent<ProductAdded>]
public class ProductReadModel
{
public Guid Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
using Cratis.Chronicle.Concepts.Events;
[EventType]
public record ProductAdded(Guid ProductId, string Name, decimal Price);
// Now valid
[FromEvent<ProductAdded>]
public class ProductReadModel
{
public Guid Id { get; set; }
public string Name { get; set; }
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