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 ...
随机推荐
- uitableview 刷新一行
ios UITableview 刷新某一行 或 section //一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWith ...
- 字典树 HDU 1251 统计难题
;} 之前写的#include<iostream> #include<algorithm> #include<stdio.h> using namespace st ...
- 【LeetCode】删除链表的倒数第N个节点
给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点. 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二个节点后,链表变为 ...
- Charles进行HTTPS抓包(iOS为例)
各种抓包工具的原理都是一样的,使用方面也都是差不多的,因为最近在用Mac,所以抓包工具开始用Charles了,记录一下抓取HTTPS的步骤. 连接代理, 开启抓包工具, 手机设置代理服务器,端口号(默 ...
- RabbitMQ高级应用
高级应用一: 手动模式和自动应答模式 1. 了确保消息不会丢失,RabbitMQ支持消息应答.消费者发送一个消息应答,告诉RabbitMQ这个消息已经接收并且处理完毕了.RabbitMQ就可以删除它了 ...
- Docker-为镜像添加SSH服务
进入容器的办法有很多,包括exec.attach等命令,但是这些命令都无法解决远程管理容器的问题,因此,需要SSH的支持 基于commit命令创建 docker提供了docker commit命令,支 ...
- JQUERY获取html标签自定义属性值或data值
//获取属性值 1 <div id="text" value="黑哒哒的盟友"><div> jQuery取值: $("#tex ...
- 图解Skip List——本质是空间换时间的数据结构,在lucene的倒排列表,bigtable,hbase,cassandra的memtable,redis中sorted set中均用到
Skip List的提出已有二十多年[Pugh, W. (1990)],却依旧应用广泛(Redis.LevelDB等).作为平衡树(AVL.红黑树.伸展树.树堆)的替代方案,虽然它性能不如平衡树稳定, ...
- Java_异常_03_ java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedObjectPoolFactory
异常信息: java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedObjectPoolFactory 原因: 我用的是commons ...
- Qt Create 4.6.2无法自动生成Android Kit
开发环境: OS,Microsoft Windows [Version 10.0.17134.523] Qt,5.11.1 Qt Creator,4.6.2 JDK,1.8.0_181 Android ...