为什么 DataAnnotation MaxLength(8192) 不起作用?
Why does DataAnnotation MaxLength(8192) not work?
我正在使用 C# 中的 Entity Framework 6.1.3 开发一个项目,我想对某些二进制数据设置最大限制。
[MaxLength(8192)]
不起作用这是一个错误吗?它似乎有一个上限。
[MaxLength(4096)]
效果出人意料?
我是否正确使用了 DataAnnotations?
//[MaxLength(4096)] <-- this works
[MaxLength(8192)]
public Byte[] MediaData {get; set;}
结果:
MediaData = c.Binary()
预计:
MediaData = c.Binary(maxLength: )
也试过了
[MaxLength(8192)] // this does not work either
public string Text {get; set;}
我可以手动修复它,但令我恼火的是 DataAnnotations 无法自动运行。你的 experiences/recommendations 和 DataAnnotations 是什么?
来自MSDN,看粗体部分:D
对于字符串部分:
nvarchar [ ( n | max ) ]
Variable-length Unicode string data.
n defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size, in bytes, is two times the actual length of data entered + 2 bytes. The ISO synonyms for nvarchar are national char varying and national character varying.
对于二进制部分:
varbinary [ ( n | max) ]
Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length. The ANSI SQL synonym for varbinary is binary varying.
所以这里其实有一个限制。
我正在使用 C# 中的 Entity Framework 6.1.3 开发一个项目,我想对某些二进制数据设置最大限制。
[MaxLength(8192)]
不起作用这是一个错误吗?它似乎有一个上限。
[MaxLength(4096)]
效果出人意料?
我是否正确使用了 DataAnnotations?
//[MaxLength(4096)] <-- this works
[MaxLength(8192)]
public Byte[] MediaData {get; set;}
结果:
MediaData = c.Binary()
预计:
MediaData = c.Binary(maxLength: )
也试过了
[MaxLength(8192)] // this does not work either
public string Text {get; set;}
我可以手动修复它,但令我恼火的是 DataAnnotations 无法自动运行。你的 experiences/recommendations 和 DataAnnotations 是什么?
来自MSDN,看粗体部分:D
对于字符串部分:
nvarchar [ ( n | max ) ] Variable-length Unicode string data. n defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size, in bytes, is two times the actual length of data entered + 2 bytes. The ISO synonyms for nvarchar are national char varying and national character varying.
对于二进制部分:
varbinary [ ( n | max) ] Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length. The ANSI SQL synonym for varbinary is binary varying.
所以这里其实有一个限制。