【译】第19节---数据注解-NotMapped
NotMapped属性可以应用于类的属性。 默认的Code-First约定为包含getter和setter的所有属性创建一个列。 NotMapped属性覆盖此默认约定。 你可以将NotMapped属性应用于不希望在数据库表中创建列的属性。
请看以下示例:
using System.ComponentModel.DataAnnotations; public class Student
{
public Student()
{ } public int StudentId { get; set; } public string StudentName { get; set; } [NotMapped]
public int Age { get; set; }
}
如上例所示,NotMapped属性应用于Student类的Age属性。 所以,Code First不会创建一列来存储学生表中的Age信息,如下所示:

Code First还不会为没有getter或setter的属性创建一列。 在以下示例中,Code-First将不会为FirstName和Age属性创建列:
using System.ComponentModel.DataAnnotations; public class Student
{
public Student()
{ }
private int _age = ; public int StudentId { get; set; } public string StudentName { get; set; } public string FirstName { get{ return StudentName;} }
public string Age { set{ _age = value;} } }
【译】第19节---数据注解-NotMapped的更多相关文章
- 【译】第20节---数据注解-InverseProperty
原文:http://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in-co ...
- 【译】第18节---数据注解-ForeignKey
原文:http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-fi ...
- 【译】第17节---数据注解-Column
原文:http://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-first. ...
- 【译】第16节---数据注解-Table
原文:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first.a ...
- 【译】第15节---数据注解-StringLength
原文:http://www.entityframeworktutorial.net/code-first/stringlength-dataannotations-attribute-in-code- ...
- 【译】第14节---数据注解-MaxLength/MinLength
原文:http://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribute-i ...
- 【译】第13节---数据注解-Required
原文:http://www.entityframeworktutorial.net/code-first/required-attribute-dataannotations-in-code-firs ...
- 【译】第12节---数据注解-ConcurrencyCheck
原文:http://www.entityframeworktutorial.net/code-first/concurrencycheck-dataannotations-attribute-in-c ...
- 【译】第11节---数据注解-TimeStamp
原文:http://www.entityframeworktutorial.net/code-first/TimeStamp-dataannotations-attribute-in-code-fir ...
随机推荐
- Redis 的 5 个常见应用场景
前言Redis 是一个强大的内存型存储,具有丰富的数据结构,使其可以应用于很多方面,包括作为数据库.缓存.消息队列等等. 如果你的印象中Redis只是一个 key-value 存储,那就错过了Redi ...
- ref 参数与out参数
变量作为参数传给方法,同时希望在方法执行完成后对参数,反应到变量上面.就需要用到ref和out这两个参数. ref参数:在 传入前必须先初始化 out参数:不需要做预先的处理
- Windows Services(NT)
本文主要记录什么是Windows Service,及其主要组成?并通过一个列子来创建一个Windows Services,同时,记录几个在查资料碰到的问题. Windows Services全文简称N ...
- Django框架----模板继承和静态文件配置
母板 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8& ...
- ogg 12.3 中 format release的变化
Non-CDB databases with compatibility set to 12.1, FORMAT RELEASE 12.2 or above is supported. Non-CDB ...
- 左移和右移运算符<< >>
左移的符号为<< 首先来个简单的例子 求8左移两位的值 8<<2 首先 将十进制的8转为二进制的数 倒序输出----> 1000 1000 左移两位 ...
- shell 多行注释 块注释
转自 https://www.cnblogs.com/emanlee/p/3749911.html 1 : ' 被注释的多行内容 ' 2 :<<eof 被注释的多行内容 eof 3 :&l ...
- shell IFS
在bash中IFS是内部的域分隔符,manual中对其的叙述如下:IFS The Internal Field Separator that is used for word splitting af ...
- Linux三剑客grep、sed、awk
grep grep file grep -i file grep -v file
- python的os模块中的os.walk()函数
os.walk('path')函数对于每个目录返回一个三元组,(dirpath, dirnames, filenames), 第一个是路径,第二个是路径下面的目录,第三个是路径下面的文件 如果加参数t ...