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的更多相关文章

  1. Entity Framework Code-First(9.6):DataAnnotations - StringLength Attribute

    DataAnnotations - StringLength Attribute: StringLength attribute can be applied to a string type pro ...

  2. Entity Framework Code-First(9.5):DataAnnotations - MaxLength Attribute

    DataAnnotations - MaxLength Attribute: MaxLength attribute can be applied to a string or array type ...

  3. Entity Framework Code-First(9.9):DataAnnotations - ForeignKey Attribute

    DataAnnotations - ForeignKey Attribute: ForeignKey attribute can be applied to properties of a class ...

  4. Entity Framework Code-First(9.8):DataAnnotations - Column Attribute

    DataAnnotations - Column Attribute: Column attribute can be applied to properties of a class. Defaul ...

  5. Entity Framework Code-First(9.7):DataAnnotations - Table Attribute

    DataAnnotations - Table Attribute: Table attribute can be applied to a class. Default Code-First con ...

  6. Entity Framework Code-First(9.2):DataAnnotations - TimeStamp Attribute

    DataAnnotations - TimeStamp Attribute: TimeStamp attribute can be applied to only one byte array pro ...

  7. Entity Framework Code-First(9.1):DataAnnotations - Key Attribute

    DataAnnotations - Key Attribute: Key attribute can be applied to properties of a class. Default Code ...

  8. 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 ...

  9. Entity Framework Code-First(9.3):DataAnnotations - ConcurrencyCheck Attribute

    ConcurrencyCheck Attribute: ConcurrencyCheck attribute can be applied to a property of a domain clas ...

随机推荐

  1. China sets economic reform priorities for 2015

    BEIJING -- China's State Council, the cabinet, on Monday unveiled this year's priorities for economi ...

  2. Vim 替换命令

    一,":substitute"的使用 :substitute 命令可以对一个指定范围的区域执行替换操作,可以简写为:s ,它的通用形式如下: :[range]substitute/ ...

  3. fastjson 格式化自定义选项

    QuoteFieldNames———-输出key时是否使用双引号,默认为true WriteMapNullValue——–是否输出值为null的字段,默认为false WriteNullNumberA ...

  4. Oracle的select检索数据

    --Select语法 select [distinct | All] select_list from table_list [where_clause] [group_by_clause] [Hav ...

  5. codeforces 710B B. Optimal Point on a Line(数学)

    题目链接: B. Optimal Point on a Line 题意: 给出n个点,问找出一个点使得这个点到所有的点的距离和最小; 思路: 所有点排序后的中位数;这是一个结论; AC代码: #inc ...

  6. SQL关联查询中on与where

    微信公众号:刺刺刺猬的优雅 前段时间,做一个查询,打算用left join查询存在于A表但不存在于B表记录,但怎么查都不对,原因是把所有filter全部放在了where语句中,因此回头看了资料,记录一 ...

  7. 关于linux 安装 python pymssql模块

    需要先安装freetds是一个开源的C程序库,它可以实现在Linux系统下访问操作微软的SQL数据库.可以用在Sybase的db-lib或者ct-lib库,在里面也包含了一个ODBC的库.允许许多应用 ...

  8. AngularJS方法 —— angular.bind

    描述: 上下文,函数以及参数动态绑定,返回值为绑定之后的函数. 其中args是可选的动态参数,self在fn中使用this调用. 使用方法: angular.bind(self,fn,args ); ...

  9. Ubuntu下locale文件

    March 7, 2015 11:44 PM locale文件 关于locale文件的设定 locale 是国际化与本土化过程中的一个非常重要的概念,个人认为,对于中文用户来说,通常会涉及到的国际化或 ...

  10. Oracle 12c 多租户 手工创建 pdb 与 手工删除 pdb

    实验环境: SQL> select * from v$version;BANNER                                                         ...