国产探花免费观看_亚洲丰满少妇自慰呻吟_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框架入門

下一篇:初次來訪

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 望奎县| 南安市| 宜兴市| 永善县| 安新县| 佛冈县| 绍兴市| 陕西省| 霍山县| 长乐市| 栖霞市| 临泉县| 敦化市| 屏山县| 儋州市| 怀远县| 贵阳市| 沐川县| 阜康市| 德钦县| 收藏| 六盘水市| 朔州市| 邛崃市| 泸州市| 蓝山县| 卢氏县| 平武县| 濮阳市| 垦利县| 吕梁市| 微博| 吉木萨尔县| 长春市| 四子王旗| 措勤县| 措勤县| 峨眉山市| 广平县| 赣州市| 上虞市|