【译】第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 ...
随机推荐
- bzoj4448 情报传递
题目链接 离线+树上主席树,主席树维护时间标记 注意查询时如果c<0要把c赋为0: #include<iostream> #include<cstdio> #includ ...
- Symfony2 学习笔记之系统路由
mfony2 学习笔记之系统路由 漂亮的URL绝对是一个严肃的web应用程序必须做到的,这种方式使index.php?article_id=57这类的丑陋URL被隐藏,由更受欢迎的像 /read/ ...
- python-数据分析与展示(Numpy、matplotlib、pandas)---2
笔记内容整理自mooc上北京理工大学嵩天老师python系列课程数据分析与展示,本人小白一枚,如有不对,多加指正 1.python自带的图像库PIL 1.1常用API Image.open() ...
- Com类型
/* VARIANT STRUCTURE * * VARTYPE vt; * WORD wReserved1; * WORD wReserved2; * WORD wReserved3; * unio ...
- Java Eclipse和MyEclipse快捷键
摘自:http://www.cnblogs.com/lsy131479/p/8487379.html 首先: 常用快捷键 alt+/ - - 万能快捷键 Ctrl+1 - - 快速修复 Eclip ...
- ui-router .state参数配置
.state('页面被引用时的变量名',{ template: '<h1>My Contacts</h1>',//被应用时插入的模板,状态被激活时,它的模板会自动插入到父状态对 ...
- 大数据自学3-Windows客户端DbVisualizer/SQuirreL配置连接hive
前面已经学习了将数据从Sql Server导入到Hive DB,并在Hue的Web界面可以查询,接下来是配置客户端工具直接连Hive数据库,常用的有DbVisualizer.SQuirreL SQL ...
- Spring Advice
Spring AOP(面向方面编程)框架,用于在模块化方面的横切关注点.简单得说,它只是一个拦截器拦截一些过程,例如,当一个方法执行,Spring AOP 可以劫持一个执行的方法,在方法执行之前或之后 ...
- JavaScript笔记 #07# 用js写算法
算法盒子初代(为了提高学习算法的热情...) 效果图: 所有代码放在单个html中: <!DOCTYPE html> <html> <head> <meta ...
- 通过RMAN 识别失败数据库损坏的对象
背景 业务起不来,读取数据库时报坏块,无法读取数据 数据库版本:11.2.0.3 数据库无备份,无归档 1. 识别坏块 执行以下命令后,rman 会把坏块信息统计到 v$database_block_ ...