Table of Contents

ARC0001: Incorrect query method signature on ReadModel

Rule

Query methods on types with [ReadModel] must return the ReadModel type, a collection, Task, IAsyncEnumerable, or ISubject of the ReadModel type.

Severity

Error

Valid Return Types

Query methods must return one of the following:

ReadModel
IEnumerable<ReadModel>
List<ReadModel>
ReadModel[]
Task<ReadModel>
Task<IEnumerable<ReadModel>>
IAsyncEnumerable<ReadModel>
ISubject<ReadModel>
ISubject<IEnumerable<ReadModel>>

Example

Violation

[ReadModel]
public class User
{
    public Guid Id { get; set; }
    public string Name { get; set; }

    // ARC0001: Invalid return type
    public static string GetName(Guid id)
    {
        return "name";
    }
}

Fix

[ReadModel]
public class User
{
    public Guid Id { get; set; }
    public string Name { get; set; }

    public static User GetById(Guid id) => new();

    public static IEnumerable<User> GetAll() => [];

    public static Task<User> GetByIdAsync(Guid id) => Task.FromResult(new User());
}

Why This Rule Exists

ReadModel query methods form the public query surface of a ReadModel. Standardized return types ensure:

  • The runtime can recognize and execute queries consistently.
  • Query results are predictable and can be composed with async patterns.
  • Streaming and reactive query patterns are supported where appropriate.
  • ARC0002: Missing [Command] attribute on command-like type