簡體   English   中英

如何首先使用實體​​框架代碼指定字段的最大列長度

[英]How do I specify the maximum column length of a field using entity framework code first

創建表時是否有可用的屬性? 我試過[StringLength]但似乎被忽略了。

 public class EntityRegister
 {
     public int Id { get; set; }
     [StringLength(450)]
     public string Name { get; set; }
 }

或者,您可以在Fluent API上手動執行此操作

使用HasMaxLength(450)

或者如果需要Data Annotation ,請使用MaxLengthMinLength屬性

public class EntityRegister
{
    public int Id { get; set; }
    [MaxLength(450)]
    public string Name { get; set; }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM