【译】第15节---数据注解-StringLength
StringLength属性可以应用于类的字符串类型属性。 EF Code First将设置StringLength属性中指定的列的大小。 请注意,它也可以与ASP.Net MVC一起用作验证属性。
请看以下示例:
using System.ComponentModel.DataAnnotations; public class Student
{
public Student()
{ }
public int StudentID { get; set; } [StringLength()]
public string StudentName { get; set; } }
如上面的代码所示,我们已经将StringLength属性应用于StudentName。 所以,Code-First将在Student表中创建一个nvarchar(50)列StudentName,如下所示:

如果设置的值大于指定的大小,则EF还会验证StringLength属性的属性值。
例如,如果您设置了超过50个字符长StudentName,则EF将抛出EntityValidationError。
关于StringLength和MaxLength的区别,请移步:https://stackoverflow.com/questions/5717033/stringlength-vs-maxlength-attributes-asp-net-mvc-with-entity-framework-ef-code-f
【译】第15节---数据注解-StringLength的更多相关文章
- 【译】第20节---数据注解-InverseProperty
原文:http://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in-co ...
- 【译】第19节---数据注解-NotMapped
原文:http://www.entityframeworktutorial.net/code-first/notmapped-dataannotations-attribute-in-code-fir ...
- 【译】第18节---数据注解-ForeignKey
原文:http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-fi ...
- 【译】第17节---数据注解-Column
原文:http://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-first. ...
- 【译】第16节---数据注解-Table
原文:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first.a ...
- 【译】第14节---数据注解-MaxLength/MinLength
原文:http://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribute-i ...
- 【译】第13节---数据注解-Required
原文:http://www.entityframeworktutorial.net/code-first/required-attribute-dataannotations-in-code-firs ...
- 【译】第12节---数据注解-ConcurrencyCheck
原文:http://www.entityframeworktutorial.net/code-first/concurrencycheck-dataannotations-attribute-in-c ...
- 【译】第11节---数据注解-TimeStamp
原文:http://www.entityframeworktutorial.net/code-first/TimeStamp-dataannotations-attribute-in-code-fir ...
随机推荐
- XmlDocument操作
一.基本操作:XmlDocument 写 class Program { static void Main(string[] args) { // 使用DOM操作,常用的类:XmlDocument.X ...
- qt之qmake
qt之qmake qmake 10分钟学会使用qmake 创建一个项目文件 qmake使用储存在项目(.pro)文件中的信息来决定Makefile文件中该生成什么. 一个基本的项目文件包含关于应用程序 ...
- [转载]asp.net中,<%#%>,<%=%>和<%%>分别是什么意思,有什么区别
在asp.net中经常出现包含这种形式<%%>的html代码,总的来说包含下面这样几种格式: 一. <%%> 这种格式实际上就是和asp的用法一样的,只是asp中里面是vbsc ...
- jboss 报错处理及端口修改
执行文件 ./shutdown.sh -S 后 重启jboss 执行 ./run.sh -Djboss.bind.address=192.168.132.129 & 如果一台机器安装多个jbo ...
- mysql03
查询的列不在同一表中必须使用连接内连接,外链接 -- 输出学生姓名以及对应的年级名称 内连接 select studentName,gradeName from student inner join ...
- 在MyEclipse中使用javadocAPI文档
开始啦 1.打开MyEclipse,选中要导出的项目,右击Exprot弹出窗口,选择java----javadoc点击next到下一界面. 2.选出要导出的项目或要添加的项目,在browse中选择路径 ...
- 新建web项目myeclipse基本设置
1. General --> Workspace --> UTF-82. General --> Editors --> Associations --> JSP --& ...
- 计算概论(A)/基础编程练习(数据成分)/1:短信计费
#include<stdio.h> int main() { // 输入当月发送短信的总次数n和每次短信的字数words int n,words; scanf("%d" ...
- hiho一下 第144周
题目1 : 机会渺茫 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi最近在追求一名学数学的女生小Z.小Z其实是想拒绝他的,但是找不到好的说辞,于是提出了这样的要求: ...
- How to Get Text inside a Canvas using Webdriver or Protractor
https://stackoverflow.com/questions/43609429/how-to-get-text-inside-a-canvas-using-webdriver-or-prot ...