【译】第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 ...
随机推荐
- python 将一个JSON 字典转换为一个Python 对象
将一个JSON 字典转换为一个Python 对象例子 >>> s='{"name":"apple","shares":50 ...
- ETL面试题集锦
1. What is a logical data mapping and what does it mean to the ETL team? 什么是逻辑数据映射?它对ETL项目组的作用是什么? 答 ...
- scrapy_novel_python
# _*_ coding:UTF _8_ from bs4 import BeautifulSoup import requests,sys class downloader(object): def ...
- 如何使用Wisdom RESTClient定制满足您个性化需求的API文档?
Wisdom RESTClient 支持自动化测试RESTful API,输出精美的测试报告,生成精美的RESTful API文档. 这里介绍一下如何定制个性化的RESTful API文档. 定制个性 ...
- Error: could not open `C:\Java\jre7\lib\amd64\jvm.cfg'
在运行cmd黑窗口时候出现:Error: could not open `C:\Java\jre7\lib\amd64\jvm.cfg'这样的错误的时候,本人没有删除任何文件,只是重新配置了一下jdk ...
- 基于opencv和QT的摄像头采集代码( GoQTtemplate3持续更新)
在Linux操作系统上,编写带界面的图像处理程序,选择opencv+QT是一种很好的选择.GoQTtemplate3是我为编写Linux下图像处理程序实现的框架,希望能够为大家解决Linux环境下桌面 ...
- noip模拟题 2017.10.28 -kmp -Tarjan -鬼畜的优化
题目大意 给定A串,选择A串的前lB个字符作为B串,再在B串后增加一个字符,问最长的相等的A串前缀和B串的后缀. Solution 1(KMP) 用1个奇怪的字符连接A串和B串,再用KMP求最长公共前 ...
- VC++ 使用ShellExecute函数调用邮箱客户端发送邮件(可以带附件)
之前写过一篇博文,通过MAPI实现调用邮箱客户端发送邮件带附件,当时对ShellExecute研究不深,以为ShellExecute不能带附件,因为项目需求原因(MAPI只能调用Foxmail和O ...
- 【python014--字符串内置函数】
一.实现跨越多行的字符串 1.采用双引号实现 str1 = ""待我长发及腰,将军归来可好?此身君子意逍遥,怎料山河萧萧天光乍破遇,暮雪白头老寒剑默听奔雷,长枪独守空豪醉卧沙场君莫 ...
- Base64编码为什么会使数据量变大?
当把byte[]通过Convert.ToBase64String转换成Base64编码字符串时数据量明显变大,为何呢?这里就得先探究一下什么是Base64编码. Base64编码的思想是是采用64个基 ...