Entity Framework Code-First(9.6):DataAnnotations - StringLength Attribute
DataAnnotations - StringLength Attribute:
StringLength attribute can be applied to a string type property of a class. EF Code-First will set the size of a column as specified in StringLength attribute. Note that it can also be used with ASP.Net MVC as a validation attribute.
Consider the following example.
using System.ComponentModel.DataAnnotations; public class Student
{
public Student()
{ }
public int StudentID { get; set; } [StringLength()]
public string StudentName { get; set; } }
As you can see in the above code, we have applied StringLength attribute to StudentName. So, Code-First will create a nvarchar(50) column StudentName in the Student table as shown below.
Entity Framework also validates the value of a property for StringLength attribute if you set the value more than the specified size. For example, if you set more than 50 chars long StudentName then EF will throw EntityValidationError.
Entity Framework Code-First(9.6):DataAnnotations - StringLength Attribute的更多相关文章
- Entity Framework Code-First(9.5):DataAnnotations - MaxLength Attribute
DataAnnotations - MaxLength Attribute: MaxLength attribute can be applied to a string or array type ...
- Entity Framework Code-First(9.10):DataAnnotations - NotMapped Attribute
DataAnnotations - NotMapped Attribute: NotMapped attribute can be applied to properties of a class. ...
- Entity Framework Code-First(9.9):DataAnnotations - ForeignKey Attribute
DataAnnotations - ForeignKey Attribute: ForeignKey attribute can be applied to properties of a class ...
- Entity Framework Code-First(9.8):DataAnnotations - Column Attribute
DataAnnotations - Column Attribute: Column attribute can be applied to properties of a class. Defaul ...
- Entity Framework Code-First(9.7):DataAnnotations - Table Attribute
DataAnnotations - Table Attribute: Table attribute can be applied to a class. Default Code-First con ...
- Entity Framework Code-First(9.2):DataAnnotations - TimeStamp Attribute
DataAnnotations - TimeStamp Attribute: TimeStamp attribute can be applied to only one byte array pro ...
- Entity Framework Code-First(9.1):DataAnnotations - Key Attribute
DataAnnotations - Key Attribute: Key attribute can be applied to properties of a class. Default Code ...
- Entity Framework Code-First(9.4):DataAnnotations - Required Attribute
Required attribute can be applied to a property of a domain class. EF Code-First will create a NOT N ...
- Entity Framework Code-First(9.3):DataAnnotations - ConcurrencyCheck Attribute
ConcurrencyCheck Attribute: ConcurrencyCheck attribute can be applied to a property of a domain clas ...
随机推荐
- zabbix实现mysql数据库的监控(二)
上章我们把zabbix的服务端和客户端都部署完成了,本章接着进行两部分的设置: 1 添加对mysql数据库主机的监控 2 添加对mysql数据库的监控 一.对数据库服务器主机监控 1 创建主机 步 ...
- LINQ 学习路程 -- 查询操作 OfType
OfType操作根据集合中的元素是否是给定的类型进行筛选 IList mixedList = new ArrayList(); mixedList.Add(); mixedList.Add(" ...
- ML2 Extension Manager
The extension manager for ML2 was introduced in Juno (more details can be found in the approvedspec) ...
- jQuery与javascript库
[jquery-javascript库] 为了简化javascript的开发,诞生了javascript程序库,他封装了很多预定的对象和实用函数.下面是几种流行的javascript程序库:proto ...
- A N EAR -D UPLICATE D ETECTION A LGORITHM T O F ACILITATE D OCUMENT C LUSTERING——有时间看看里面的相关研究
摘自:http://aircconline.com/ijdkp/V4N6/4614ijdkp04.pdf In the syntactical approach we define binary at ...
- adb命令(二)
1.获取手机型号指令 adb shell cat /system/build.prop | findstr "ro.product.model" 2.获取手机处理器信息 adb s ...
- 第二章 python基础(三)
第十六节 MySQLdb win64位安装python-mysqldb1.2.5 ubuntu下安装MySQLdb sudo apt-get install python-MySQLdb 导入MySQ ...
- BEC listen and translation exercise 46
录音文件 https://pan.baidu.com/s/1qYYZGWO The process of learning and exploring a subject can lead to a ...
- JAVA标号与continue,break
可以给语句块加标号赋予它们名称,标号位于语句之前.标号只能被continue和break引用.格式如下: label:statement 语句前只允许加一个标号,标号后面不能跟大括号. ...
- 在Windows下搭建Android开发环境
随着移动互联网的迅速发展,前端的概念已发生很大的变化,已不仅仅局限在网页端.而Android系统作为智能机市场的老大,作为前端开发工程师, 非常有必要了解和学习.但面对众多学习资料,站在前端开发工程师 ...