简体   繁体   English

指定MaxLength时,实体框架使用nvarchar(max)

[英]Entity Framework uses nvarchar (max) when MaxLength is specified

I have specified a text field's MaxLength as 4096 with EF fluent api in order to limit its length: 我已经使用EF流畅的api将文本字段的MaxLength指定为4096以限制其长度:

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

But for some reason in SQL Server, the column becomes nvarchar (max) . 但由于某些原因,在SQL Server中,该列变为nvarchar (max)

Just for test if I specify 2048 to make sure that SQL Server gets updated 仅供测试,如果我指定2048以确保SQL Server得到更新

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) 所以我的问题为什么EF在MaxLength(4096)时设置sql nvarchar (max) MaxLength(4096)

I think it's SQL Server limits. 我认为这是SQL Server的限制。 msdn says msdn

Variable-length Unicode string data. 可变长度的Unicode字符串数据。 n defines the string length and can be a value from 1 through 4,000 . n定义字符串长度,可以是1到4,000之间的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 MaxLength 属性指定 NVARCHAR(MAX) - Using MaxLength attribute to specify NVARCHAR(MAX) 实体框架5 MaxLength - entity framework 5 MaxLength 为什么Entity Framework不为nvarchar(MAX)字段返回修剪后的字符串? - Why does Entity Framework not return a trimmed string for a nvarchar(MAX) field? C#实体框架-长字符串未作为NVARCHAR(MAX)保留 - C# Entity Framework - Long String not being persisted as NVARCHAR(MAX) 将 nvarchar 值“EnumValue”转换为数据类型 int 时,Entity Framework Core 3.1 枚举转换失败 - Entity Framework Core 3.1 Enum Conversion failed when converting the nvarchar value 'EnumValue' to data type int 使用Entity Framework Code First和DBMigration时生成ntext / nvarchar列 - Generate ntext/nvarchar column when using Entity Framework Code First and a DBMigration 使用MAX的实体框架查询 - Entity Framework Query with MAX 使用max进行实体框架查询 - Entity Framework querying with max 首先为Entity Framework代码中的所有字符串设置MaxLength - Setting MaxLength for all strings in Entity Framework code first 实体框架代码First MaxLength和FixedLegth(char vs varchar) - Entity Framework Code First MaxLength and FixedLegth (char vs varchar)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM