[英]Why does DataAnnotation MaxLength(8192) not work?
I am working on a project with Entity Framework 6.1.3 in C#, and I want to set an maximum limit on some binary data. 我正在使用C#中的Entity Framework 6.1.3开发一个项目,我想对某些二进制数据设置最大限制。
[MaxLength(8192)]
does not work is this a bug? [MaxLength(8192)]
不起作用,这是一个错误吗? There seems to be an upper limit to it. 似乎有一个上限。
[MaxLength(4096)]
this works surprisingly? [MaxLength(4096)]
这个功能出奇吗?
Am I using DataAnnotations correctly? 我是否正确使用DataAnnotations?
//[MaxLength(4096)] <-- this works
[MaxLength(8192)]
public Byte[] MediaData {get; set;}
Result: 结果:
MediaData = c.Binary()
Expected: 预期:
MediaData = c.Binary(maxLength: )
Also tried. 也试过了。
[MaxLength(8192)] // this does not work either
public string Text {get; set;}
I could fix it manually but It annoys me that DataAnnotations does not work automatically. 我可以手动修复它,但让我烦恼的是DataAnnotations无法自动运行。 What are your experiences/recommendations with DataAnnotations?
您对DataAnnotations有何经验/建议?
from MSDN, look at the bold part :D 从MSDN,请看大胆的部分:D
for string part: 对于字符串部分:
nvarchar [ ( n | max ) ] Variable-length Unicode string data.
nvarchar [(n | max)]变长Unicode字符串数据。 n defines the string length and can be a value from 1 through 4,000 .
n定义字符串长度,可以是1到4,000之间的值 。 max indicates that the maximum storage size is 2^31-1 bytes (2 GB).
max表示最大存储大小为2 ^ 31-1字节(2 GB)。 The storage size, in bytes, is two times the actual length of data entered + 2 bytes.
存储大小(以字节为单位)是输入的数据实际长度的两倍+ 2个字节。 The ISO synonyms for nvarchar are national char varying and national character varying.
nvarchar的ISO同义词是国家字符变化和国家字符变化。
and for the binary part: 对于二进制部分:
varbinary [ ( n | max) ] Variable-length binary data.
varbinary [(n | max)] 可变长度的二进制数据。 n can be a value from 1 through 8,000.
n可以是1到8,000之间的值。 max indicates that the maximum storage size is 2^31-1 bytes.
max表示最大存储大小为2 ^ 31-1字节。 The storage size is the actual length of the data entered + 2 bytes.
存储大小是输入数据的实际长度+ 2个字节。 The data that is entered can be 0 bytes in length.
输入的数据长度可以为0个字节。 The ANSI SQL synonym for varbinary is binary varying.
varbinary的ANSI SQL同义词是二进制变化的。
so there is actually a limitation here. 所以这里实际上有一个限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.