Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why EF Core 2.2 has a default primary key set to nvarchar(450)

We are upgrading our code base from EF6.2 to EF Core 2.2, our team discovered that the default value of string based Identity key will generate a primary key column with

  • nvarchar(128) in EF 6.2 (SQL Server)
  • nvarchar(450) in EF Core 2.2 (SQL Server)

What is the reason behind this decision?

like image 679
Kuroro Avatar asked Aug 22 '19 04:08

Kuroro


1 Answers

SQL Server allows indexes up to 900 bytes. Characters in an nvarchar are 2 bytes. 2 * 450 = 900. We (the EF team) were worried about primary keys on multiple columns in EF6. In EF Core, we realized only specified characters are indexed ("var" is for varying length) so we could go all the up to 450 and it would still work so long as the total characters across all columns in the key were less than 450.

like image 126
bricelam Avatar answered Nov 02 '22 02:11

bricelam