Skip to content

Latest commit

 

History

History
39 lines (34 loc) · 1.12 KB

File metadata and controls

39 lines (34 loc) · 1.12 KB

QW0028: Prefer strongly typed identifiers over GUIDs

GUIDs are commonly used as identifiers for storing records and objects in databases.

In code, it is preferred to use strongly typed identifiers instead. This allows for strict distinction between different types of identifiers, thereby reducing primitive obsession.

If the primitive is required elsewhere in the system, making it hard or inconvenient to change it to a strongly typed identifier, decorate it with the [PrimitiveRequired] attribute. In this case the rule will not flag this property.

Strongly Typed Identifiers

Non-compliant

public sealed class MyModel
{
    public Guid Id { get; init; }
}

Compliant

public sealed class MyModel
{
    public MyModelId Id { get; init; }
}

or

public sealed class MyModel
{
    [PrimitiveRequired]
    public Guid Id { get; init; }
}