简体   繁体   English

如何首先使用实体​​框架代码指定字段的最大列长度

[英]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)

  • Configuring Properties and Types with the Fluent API 使用Fluent API配置属性和类型

or if you want Data Annotation , use MaxLength and MinLength attributes 或者如果需要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.

相关问题 使用实体框架,如何在导航属性上指定排序? - Using Entity Framework, how do I specify a sort on a navagation property? 如何将主键标识列添加到实体框架代码首先生成的模型 - How do I add a Primary Key identity column to Entity Framework Code First generated Model 如何使用Code First Entity Framework在一个字段中的数据库中存储一个整数数组? - How can I store an Array of Ints in my database, in a single field, using Code First Entity Framework? 我应该如何访问Entity Framework Code First中的计算列? - How should I access a computed column in Entity Framework Code First? 如何在Entity Framework Code First中加密数据? - How do I encrypt data in Entity Framework Code First? 如何使用C#-WPF-Entity-Framework Code First应用程序创建数据库备份? - How do I create database backups using C#-WPF-Entity-Framework Code First application? 实体框架6:如何使用代码优先迁移和FTP部署重置数据库 - Entity Framework 6: How do I reset a database using code first migrations and an FTP deploy 如何使用代码优先实体框架设置默认日期 - How do I set a default date using code first entity framework 如何使用Entity Framework代码优先映射带有复合键的继承表? - How do I map an inherited table with a composite key using Entity Framework code-first? 如何在 MVC3 和实体框架上使用 Code First 将另一个表添加到我的数据库中? - How do I add another table to my database using Code First on MVC3 and Entity Framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM