Entity Framework uses nvarchar (max) when MaxLength is specified

c# entity-framework entity-framework-6 sql-server

Question

I have specified a text field's MaxLength as 4096 with EF fluent api in order to limit its length:

this.Property(p => p.MyText).HasMaxLength(4096).IsRequired();

But for some reason in SQL Server, the column becomes nvarchar (max).

Just for test if I specify 2048 to make sure that SQL Server gets updated

this.Property(p => p.MyText).HasMaxLength(2048).IsRequired();

And this way it is works.

So my queston why EF sets sql nvarchar (max) when MaxLength(4096)

1
3
8/27/2015 1:20:40 PM

Accepted Answer

I think it's SQL Server limits. msdn says

Variable-length Unicode string data. n defines the string length and can be a value from 1 through 4,000.

5
8/27/2015 1:14:29 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow