Entity Framework Code-First(9.10):DataAnnotations - NotMapped Attribute
DataAnnotations - NotMapped Attribute:
NotMapped attribute can be applied to properties of a class. Default Code-First convention creates a column for all the properties which includes getters and setters. NotMapped attribute overrides this default convention. You can apply NotMapped attribute to a property which you do NOT want to create a column in a database table for.
Consider the following example.
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; }
}
As you can see in the above example, NotMapped attribute is applied to Age property of the Student class. So, Code First will not create a column to store Age information in the Student table as shown below.
Code-first also does not create a column for a property which does not have either getters or setters. Code-First will not create columns for FirstName and Age properties in the following example.
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;} } }
Entity Framework Code-First(9.10):DataAnnotations - NotMapped Attribute的更多相关文章
- Entity Framework Code-First(9.6):DataAnnotations - StringLength Attribute
DataAnnotations - StringLength Attribute: StringLength attribute can be applied to a string type pro ...
- Entity Framework Code-First(9.5):DataAnnotations - MaxLength Attribute
DataAnnotations - MaxLength Attribute: MaxLength attribute can be applied to a string or array type ...
- Entity Framework Code-First(9.9):DataAnnotations - ForeignKey Attribute
DataAnnotations - ForeignKey Attribute: ForeignKey attribute can be applied to properties of a class ...
- Entity Framework Code-First(9.8):DataAnnotations - Column Attribute
DataAnnotations - Column Attribute: Column attribute can be applied to properties of a class. Defaul ...
- Entity Framework Code-First(9.7):DataAnnotations - Table Attribute
DataAnnotations - Table Attribute: Table attribute can be applied to a class. Default Code-First con ...
- Entity Framework Code-First(9.2):DataAnnotations - TimeStamp Attribute
DataAnnotations - TimeStamp Attribute: TimeStamp attribute can be applied to only one byte array pro ...
- Entity Framework Code-First(9.1):DataAnnotations - Key Attribute
DataAnnotations - Key Attribute: Key attribute can be applied to properties of a class. Default Code ...
- Entity Framework Code-First(9.4):DataAnnotations - Required Attribute
Required attribute can be applied to a property of a domain class. EF Code-First will create a NOT N ...
- Entity Framework Code-First(9.3):DataAnnotations - ConcurrencyCheck Attribute
ConcurrencyCheck Attribute: ConcurrencyCheck attribute can be applied to a property of a domain clas ...
随机推荐
- java面试_数据库
1.group by 根据表里的字段名分类,相同字段名只显示一行记录,通常与聚集函数max.min合用选择最大值最小值,或者与having合用筛选,结果按照group by的字段排序 例:select ...
- <Perl算法小菜>排序加速--Schwatzian变换及Guttman-Rosler变换
原创博客,转载请联系博主! perl里的数据都是以双精度为单元存储的,也就是相当于C/Cpp中的double型,而正则的解析是由perl内置的正则引擎完成的,那么除了重写一个属于自己的排序方法之外,我 ...
- LINQ 学习路程 -- 查询操作 ThenBy & ThenByDescending
IList<Student> studentList = new List<Student>() { , StudentName = } , , StudentName = } ...
- EntityFramework 学习 一 创建实体数据模型 Create Entity Data Model
1.用vs2012创建控制台程序 2.设置项目的.net 版本 3.创建Ado.net实体数据模型 3.打开实体数据模型向导Entity Framework有四种模型选择 来自数据库的EF设计器(Da ...
- ES doc_values介绍2——本质是field value的列存储,做聚合分析用,ES默认开启,会占用存储空间
一.doc_values介绍 doc values是一个我们再三重复的重要话题了,你是否意识到一些东西呢? 搜索时,我们需要一个“词”到“文档”列表的映射 排序时,我们需要一个“文档”到“词“列表的映 ...
- Quality
- JSTL前台报错
报错信息: jsp页面报错 Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core&qu ...
- bzoj-2458 2458: [BeiJing2011]最小三角形(计算几何+分治)
题目链接: 2458: [BeiJing2011]最小三角形 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1101 Solved: 380 Des ...
- ACM学习历程—HDU5521 Meeting(图论)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是一个人从1开始走,一个人从n开始走.让最 ...
- 【LeetCode】066. Plus One
题目: Given a non-negative integer represented as a non-empty array of digits, plus one to the integer ...