博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Entity Framework Code-First(9.4):DataAnnotations - Required Attribute
阅读量:6914 次
发布时间:2019-06-27

本文共 743 字,大约阅读时间需要 2 分钟。

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.

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.

转载于:https://www.cnblogs.com/purplefox2008/p/5644138.html

你可能感兴趣的文章
实施微服务,我们需要哪些基础框架
查看>>
Linux 简单创建用户并指定文件夹权限
查看>>
python计算器
查看>>
Linux 代理上网
查看>>
openstack cobbler Icehouse ks 配置文件
查看>>
C++基本的数据类型
查看>>
Thinkphp 5.0实战 仿百度糯米开发多商家电商平台
查看>>
oracle10 ora-12154错误的解决办法
查看>>
OpenStack 架构 - 每天5分钟玩转 OpenStack(15)
查看>>
DotProject环境搭建
查看>>
linux学习二
查看>>
关于form表单的reset功能无法还原hidden中的值
查看>>
搞PHP怎么不知道CURL呢,呵呵。。。。。
查看>>
希捷硬盘1T挂了(1)
查看>>
关闭ADOX.Catalog创建Access的链接,避免ldb锁定
查看>>
我的友情链接
查看>>
360云盘退役后 剩下的几家云存储平台要上演“饥饿游戏”了
查看>>
用Memcache缓存加速Mysql的查询
查看>>
MAC下安装redis
查看>>
我的朗科运维第六课(2)
查看>>