Skip to content

Replace int with long as ID type in samples/docs/tests #1876

@bkoelman

Description

@bkoelman

This project originally used int (32-bit) as the ID type in resources. While that's not wrong, I believe we should default to long (64-bit) in docs, samples and most tests. With many database transactions, the 2 billion limit can be reached earlier than expected, requiring a costly database migration and possible outage. A 64-bit auto-incrementing number doesn't have this limitation. Users can always choose their own ID type, but for anyone who doesn't care, this sounds like the safer default.

We should keep a few tests around, though, that still use int, so it remains covered. Models in JsonApiDotNetCoreTests/IntegrationTests/ReadWrite and JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations should not be updated, as they cover scenarios with varying ID types.

The change is basically from, for example:

public sealed class TelevisionBroadcast : Identifiable<int>

to:

public sealed class TelevisionBroadcast : Identifiable<long>

Likewise, tests that parse the ID should be updated accordingly, from:

int newShopId = int.Parse(responseDocument.Data.SingleValue.Id);

to:

long newShopId = long.Parse(responseDocument.Data.SingleValue.Id);

As well as usages to unknown IDs in tests, such as from:

int id = Unknown.StringId.Int32;

to:

long id = Unknown.StringId.Int64;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions