CHR0002: Declarative projection event type must have [EventType] attribute
Rule Description
Section titled “Rule Description”Generic type arguments in declarative projections that reference event types must be marked with the [EventType] attribute.
Severity
Section titled “Severity”Error
Example
Section titled “Example”Violation
Section titled “Violation”using Cratis.Chronicle.Projections;
// Missing [EventType] attributepublic 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));}Quick Fix
Section titled “Quick Fix”The analyzer provides a code fix that automatically adds the [EventType] attribute to the referenced type.
Why This Rule Exists
Section titled “Why This Rule Exists”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