An Enthusiastic Programmer

Data Annotation - NotMapped Attribute


As per the Code First convention, the Entity Framework will map each property which has setter and getter method to a column by default. the NotMapped attribute can override this default convention. Entity Framework will exclude the property which applied the NotMapped attribute.

Let’s look at the below illustration.

public class Student
    public int id { set; get; }

    public string name { set; get; }

    public int age { set; get; }

The Entity Framework doesn’t map the age property. Alt


The NotMapped can also be permitted to apply on a Entity name.

public class Classroom{
    public int id{set;get;}
    public List<Student> students{set;get;}
pubic class Student{
    public int id{set;get;}

we placed the NotMapped attribute above the Student Entity. the Student will not map to a table. Alt