1

TLDR; Microsoft Documentation for .HasColumnType() states "... should be the complete type name, including precision, scale, length ...". This seems to be in contradiction to this stack overflow answer - has the recommended usage changed ?

Using EF Core 3.1 (and 5), SQLite and Northwind database, following examples from MJPrice Cs8 & .Net Core 3 Chapter14, I used dotnet ef scaffold ... to create similar code and compare to the book. This tool generates a lot of .HasColumnType() methods, and no HasMaxLength() methods.

Is maximum length correctly captured when replacing .HasMaxLength(15) with .HasColumnType("nvarchar(15)") (example for the CategoryName property of Category) ?

Is .HasColumnType() unnecessary due to the way SQLite stores types and therefore only the maximum length information is really needed for this example i.e. database provider is SQLite?

DefinedRisk
  • 140
  • 9

1 Answers1

1

The documentation you pointed out is for EF Core, whereas the stackoverflow question you linked to is referring to EF 6. As you can see in the documentation, in EF 6 HasColumnType expected only the type, without precision, scale, length, etc.... So that has changed.

In any case, I don't know much about SQLite so I might be wrong here, but I believe that there is no length restriction at all. Even if you declare a size for TEXT or VARCHAR it will just ignore it.

Note that numeric arguments in parentheses that following the type name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric values.

dglozano
  • 6,369
  • 2
  • 19
  • 38