9.10 翻译系列:EF数据注解特性之StringLength【EF 6 Code-First系列】
EF 6 Code-First系列文章目录:
- 1 翻译系列:什么是Code First(EF 6 Code First 系列)
 - 2.翻译系列:为EF Code-First设置开发环境(EF 6 Code-First系列)
 - 3.翻译系列:EF Code-First 示例(EF 6 Code-First系列)
 - 4.翻译系列:EF 6 Code-First默认约定(EF 6 Code-First系列)
 - 5.翻译系列:EF 6中数据库的初始化(EF 6 Code-First 系列)
 - 6.翻译系列:EF 6 Code-First中数据库初始化策略(EF 6 Code-First系列
 - 7.翻译系列:EF 6中的继承策略(EF 6 Code-First 系列)
 - 8.翻译系列: EF 6中配置领域类(EF 6 Code-First 系列)
 - 9.翻译系列:EF 6以及EF Core中的数据注解特性(EF 6 Code-First系列)
 - 9.1 翻译系列:数据注解特性之----Table【EF 6 Code-First 系列】
 - 9.2 翻译系列:数据注解特性之---Column【EF 6 Code First系列】
 - 9.3 翻译系列:数据注解特性之Key【EF 6 Code-First 系列】
 - 9.4 翻译系列:EF 6以及 EF Core中的NotMapped特性(EF 6 Code-First系列)
 - 9.5 翻译系列:数据注解之ForeignKey特性【EF 6 Code-First系列】
 - 9.6 翻译系列:数据注解之Index特性【EF 6 Code-First系列】
 - 9.7 翻译系列:EF数据注解特性之--InverseProperty【EF 6 Code-First系列】
 - 9.8 翻译系列:数据注解特性之--Required 【EF 6 Code-First系列】
 - 9.9 翻译系列:数据注解特性之--MaxLength 【EF 6 Code-First系列】
 - 9.10 翻译系列:EF数据注解特性之StringLength【EF 6 Code-First系列】
 - 9.11 翻译系列:数据注解特性之--Timestamp【EF 6 Code-First系列】
 - 9.12 翻译系列:数据注解特性之ConcurrencyCheck【EF 6 Code-First系列】
 - 10.翻译系列:EF 6中的Fluent API配置【EF 6 Code-First系列】
 - 10.1.翻译系列:EF 6中的实体映射【EF 6 Code-First系列】
 - 10.2.翻译系列:使用Fluent API进行属性映射【EF 6 Code-First】
 - 11.翻译系列:在EF 6中配置一对零或者一对一的关系【EF 6 Code-First系列】
 - 12.翻译系列:EF 6 中配置一对多的关系【EF 6 Code-First系列】
 - 13.翻译系列:Code-First方式配置多对多关系【EF 6 Code-First系列】
 - 14.翻译系列:从已经存在的数据库中生成上下文类和实体类【EF 6 Code-First系列】
 - 15.翻译系列:EF 6中的级联删除【EF 6 Code-First 系列】
 - 16.翻译系列:EF 6 Code -First中使用存储过程【EF 6 Code-First系列】
 - 17.翻译系列:将Fluent API的配置迁移到单独的类中【EF 6 Code-First系列】
 - 18.翻译系列:EF 6 Code-First 中的Seed Data(种子数据或原始测试数据)【EF 6 Code-First系列】
 - 19.翻译系列:EF 6中定义自定义的约定【EF 6 Code-First约定】
 - 20.翻译系列:Code-First中的数据库迁移技术【EF 6 Code-First系列】
 - 20.1翻译系列:EF 6中自动数据迁移技术【EF 6 Code-First系列】
 - 20.2.翻译系列:EF 6中基于代码的数据库迁移技术【EF 6 Code-First系列】
 - 21.翻译系列:Entity Framework 6 Power Tools【EF 6 Code-First系列】
 
StringLength特性可以应用于实体的string类型的属性上,它指定了属性的所允许的最大字符长度,然后对应在数据库中就生成相应长度的数据列(在SQL Server数据库中是,nvarchar类型)。
using System.ComponentModel.DataAnnotations;
public class Student
{
    public int StudentID { get; set; }
    [StringLength(50)]
    public string StudentName { get; set; }
}
上面的例子中,我们将StringLength特性应用在StudentName属性上,所以EF将会在StudentName列,映射为nvarchar(50):

EF会验证StudentName的属性值的长度,如果大于50个字符长度,就报错:EF 6中:System.Data.Entity.Validation.DbEntityValidationException,EF Core中Microsoft.EntityFrameworkCore.DbUpdateException
请注意:StringLength特性,还可以用在ASP.NET MVC中,用来验证属性的值,了解更多,请看这篇文章:Implement Validations in ASP.NET MVC 。
9.10 翻译系列:EF数据注解特性之StringLength【EF 6 Code-First系列】的更多相关文章
- 9.9 翻译系列:数据注解特性之--MaxLength 【EF 6 Code-First系列】
		
原文链接:https://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribut ...
 - 9.7 翻译系列:EF数据注解特性之--InverseProperty【EF 6 Code-First系列】
		
原文链接:https://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in ...
 - 9.3 翻译系列:数据注解特性之Key【EF 6 Code-First 系列】
		
原文链接:http://www.entityframeworktutorial.net/code-first/key-dataannotations-attribute-in-code-first.a ...
 - 9.2 翻译系列:数据注解特性之---Column【EF 6 Code First系列】
		
原文链接:http://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-firs ...
 - 9.1 翻译系列:数据注解特性之----Table【EF 6 Code-First 系列】
		
原文地址:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first ...
 - 9.8 翻译系列:数据注解特性之--Required 【EF 6 Code-First系列】
		
原文链接:https://www.entityframeworktutorial.net/code-first/required-attribute-dataannotations-in-code-f ...
 - 9.11 翻译系列:数据注解特性之--Timestamp【EF 6 Code-First系列】
		
原文链接:https://www.entityframeworktutorial.net/code-first/TimeStamp-dataannotations-attribute-in-code- ...
 - 9.12 翻译系列:数据注解特性之ConcurrencyCheck【EF 6 Code-First系列】
		
原文链接:https://www.entityframeworktutorial.net/code-first/concurrencycheck-dataannotations-attribute-i ...
 - 9.翻译系列:EF 6以及EF Core中的数据注解特性(EF 6 Code-First系列)
		
原文地址:http://www.entityframeworktutorial.net/code-first/dataannotation-in-code-first.aspx EF 6 Code-F ...
 
随机推荐
- 01 Python初识
			
基础: 1.后缀名是py ATT: 单个文件执行,后缀无所谓 2.两种执行方式 终端 python+文件路径 解释器内部: 直接执行 3.解释器路径: #/usr/bin/env pyth ...
 - win10 KMS命令激活步骤<转>
			
三.win10 KMS命令激活步骤如下: 1.右键点击开始图标,弹出这个菜单,选择[windows powershell(管理员)],或者命令提示符管理员: 2.打开命令窗口,复制这个命令slmgr ...
 - oracle查看被锁的表和解锁
			
--以下几个为相关表SELECT * FROM v$lock;SELECT * FROM v$sqlarea;SELECT * FROM v$session;SELECT * FROM v$proce ...
 - Python模块定义和使用
			
Python中所谓的模块就是一个Python文件,一个abc.py的文件就是一个名字叫abc的模块,一个xyz.py的文件就是一个名字叫xyz的模块.模块由代码.函数或类组成.编程中使用模块不仅可以提 ...
 - [C语言]进阶|数据类型: 整数, 浮点, 逻辑, 类型转换和条件运算
			
--------------------------------------------------------------------------------- [C语言的类型] 1. 整型(都分为 ...
 - html网页练习豆瓣网
			
html </head> <body> <!-- 头部 --> <header class="header1"> ...
 - phpcms的一些问题 乱码,安装
			
一.乱码:我这的网站出现的乱码情况:后台栏目名乱码,迁站后更新缓存,再更新栏目,内容,前台都乱码. 找了半天原因,经过本地测试,没问题,一上线就出现问题,不同点就是线上的数据库版本是mysql5.5, ...
 - C++继承中关于子类构造函数的写法
			
构造方法用来初始化类的对象,与父类的其它成员不同,它不能被子类继承(子类可以继承父类所有的成员变量和成员方法,但不继承父类的构造方法).因此,在创建子类对象时,为了初始化从父类继承来的数据成员,系统需 ...
 - 无监督学习算法-Apriori进行关联分析
			
关联分析 是无监督讯息算法中的一种,Apriori主要用来做_关联分析_,_关联分析_可以有两种形式:频繁项集或者关联规则.举个例子:交易订单 序号 商品名称 1 书籍,电脑 2 杯子,手机,手机壳, ...
 - D. Kilani and the Game(多源BFS)
			
题目来源:http://codeforces.com/contest/1105/problem/D 题意:编号为1-k的点在一张n*m的表格中依次扩散,每个结点有各自的扩散速度且只可以往上下左右四个方 ...