国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

數據注解特性--MaxLength&&MinLength

2019-11-14 13:41:26
字體:
來源:轉載
供稿:網友

MaxLength attribute can be applied to a string or array type PRoperty of a domain class. EF Code First will set the size of a column as specified in MaxLength 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; }         [MaxLength(50)]    public string StudentName { get; set; }        }        

As you can see in the above code, we have applied MaxLength attribute to StudentName. So, Code-First will create a nvarchar(50) column StudentName in the Student table as shown below.

dataannotations maxlength attribute

Entity Framework also validates the value of a property for MaxLength 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.

MinLength:

MinLength attribute is a validation attribute. It does not have an impact on the database schema. EF will throw EntityValidationError if you set a value of a string or array property less than the specified length in MinLength attribute.

MinLength attribute can also be used with MaxLength attribute as shown below.

using System.ComponentModel.DataAnnotations;    public class Student{    public Student()    {             }    public int StudentID { get; set; }         [MaxLength(50),MinLength(2)]    public string StudentName { get; set; }        }        

In the above example, StudentName can not be less than 2 chars and more than 50 chars.


上一篇:C#AOP框架入門

下一篇:初次來訪

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿合奇县| 施秉县| 定南县| 竹溪县| 中卫市| 牟定县| 龙岩市| 临清市| 鄯善县| 镇安县| 大英县| 措勤县| 赤壁市| 东明县| 巴南区| 宜宾县| 长泰县| 大洼县| 安义县| 保德县| 芒康县| 肇庆市| 曲周县| 政和县| 商都县| 石棉县| 平罗县| 黄平县| 临安市| 常宁市| 阿坝县| 永吉县| 鹰潭市| 广州市| 凭祥市| 龙川县| 馆陶县| 体育| 东城区| 合肥市| 密云县|