Entity Framework Code-First(9.4):DataAnnotations - Required Attribute
2016-07-05 16:30
477 查看
Required attribute can be applied to a property of a domain class. EF Code-First will create a NOT NULL column in a database table for a property on which we apply Required attribute. Note that it can also be used with ASP.Net MVC as a validation attribute.
Consider the following example.
As you can see in the above code, we have applied Required attribute to StudentName. So, Code First will create a NOT NULL StudentName column in the Student table as shown below.
Consider the following example.
using System.ComponentModel.DataAnnotations; public class Student { public Student() { } public int StudentID { get; set; } [Required] public string StudentName { get; set; } }
As you can see in the above code, we have applied Required attribute to StudentName. So, Code First will create a NOT NULL StudentName column in the Student table as shown below.
相关文章推荐
- iOS开发:keychain存储UUID
- java 基础:Blocking Queues的源码实现
- easyui学习(1)
- 阿里面经之解答 by cmershen(3)——String/StringBuffer/StringBuilder,Java序列化,线程安全,线程同步,ThreadLocal
- UI碎片控件之Fragment——底部导航栏的实现(方法2)
- Number Sequence(poj 1019)
- DelayQueue
- UUID和UDID
- 关于tensorflow 的数据读取线程管理QueueRunner
- PriorityQueue
- 数据库主键用 int自增序列 还是 GUID
- HTML标签marquee实现滚动效果
- Xcode莫名其妙问题could not build module 'Foundation'
- String StringBuffer StringBuilder区别(Java面试)
- UGUI解决嵌套使用多个ScrollRect时的Drag拖动冲突问题
- SeaJS与RequireJS
- NGUI 事件 (动画播放完毕调用其他方法)
- Increasing Triplet Subsequence
- UIView旋转动画
- UI开发设计