JsonApiDotNetCore icon indicating copy to clipboard operation
JsonApiDotNetCore copied to clipboard

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

Open bkoelman opened this issue 2 weeks ago • 4 comments

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;

bkoelman avatar Dec 03 '25 01:12 bkoelman

Hi @ziagham,

I’d be happy to help with this task. Please let me know if you’d like me to take this on.

Thanks!

niteshsinghal85 avatar Dec 08 '25 17:12 niteshsinghal85

Hi @niteshsinghal85, you're welcome to pick this up. Looking forward to your contribution!

bkoelman avatar Dec 09 '25 09:12 bkoelman

@bkoelman a quick question, about the benchmark , i see that in the benchmark also Identifiable<int> is used. do you want to update the benchmark also to Identifiable<long>

niteshsinghal85 avatar Dec 09 '25 10:12 niteshsinghal85

Yes

bkoelman avatar Dec 09 '25 10:12 bkoelman