[英]How do I specify the maximum column length of a field using entity framework code first
Is there an attribute I can use when creating a table ? 创建表时是否有可用的属性? I tried
[StringLength]
but it seems to be ignored. 我试过
[StringLength]
但似乎被忽略了。
public class EntityRegister
{
public int Id { get; set; }
[StringLength(450)]
public string Name { get; set; }
}
alternatively, you can manually do it on Fluent API
或者,您可以在
Fluent API
上手动执行此操作
use HasMaxLength(450)
使用
HasMaxLength(450)
or if you want Data Annotation
, use MaxLength
and MinLength
attributes 或者如果需要
Data Annotation
,请使用MaxLength
和MinLength
属性
public class EntityRegister
{
public int Id { get; set; }
[MaxLength(450)]
public string Name { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.