Primitives like int, long, and string 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.
public sealed class MyModel
{
public int Id { get; init; }
}public sealed class MyModel
{
public MyModelId Id { get; init; }
}or
public sealed class MyModel
{
[PrimitiveRequired]
public int Id { get; init; }
}