---
title: 'CHR0003: Model bound projection attribute must reference event type with [EventType] attribute'
editUrl: https://github.com/Cratis/Chronicle/edit/main/Documentation/code-analysis/CHR0003.mdx
description: Model bound projection attributes (such as FromEventAttribute<TEvent>, RemovedWithAttribute<TEvent>, etc.) must reference types that are marked with the…
---

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

## Rule Description

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

## Severity

Error

## Example

### Violation

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

```csharp
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; }
}
```

[View C# snippet source on GitHub](https://github.com/Cratis/Chronicle/blob/main/Documentation/client-snippets/code-analysis/chr0003/violation.md)

</TabItem>
</Tabs>

### Fix

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

```csharp
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; }
}
```

[View C# snippet source on GitHub](https://github.com/Cratis/Chronicle/blob/main/Documentation/client-snippets/code-analysis/chr0003/fix.md)

</TabItem>
</Tabs>

## Applicable Attributes

This rule applies to the following model bound projection attributes:
- `FromEventAttribute<TEvent>`
- `RemovedWithAttribute<TEvent>`
- `RemovedWithJoinAttribute<TEvent>`
- `JoinAttribute<TEvent>`
- `ChildrenFromAttribute<TEvent>`
- `FromEveryAttribute<TEvent>`

## Quick Fix

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

## Why This Rule Exists

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

## Related Rules

- [CHR0001](/chronicle/code-analysis/chr0001/): Event sequence append operations
- [CHR0002](/chronicle/code-analysis/chr0002/): Declarative projection event types
