You know that by using the bellow attribute we can auto generate identity of int
for each entry in case of Adding new entry:
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
If you had focused ever, Database generates unique int
numbers for each new entry, auto incremented as well, and in case of deletion, it will continue from the latest dedicated number(may be deleted), not from the latest used number in Table. This cause to have non subsequent numbers like bellow in the table:
Id Value GroupId
1 A 1
2 B 1
8 C 2//here we have 5 entry deletion
9 D 2
25 E 3//here we have 15 entry deletion
My question is: Suppose we have large number of entries to register. If the key attribute, say Id
reaches the maximum number of its type(here int
capacity equal to 2^32), Does EF or SQL server recognize that we have a lot of not used numbers as key in the Table to use them? Or not?
IDENTITY works as well with BIGINT columns, and it would be very difficult to reach the maximum value. Just replace Int32 with Int64 in the .NET code and INT with BIGINT in the database. Do not reseed the values, because they will begin from 1, and there will be duplicates.