Data Annotation - NotMapped Attribute
07 Apr 2020 | CSharp-EFAs 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; }
[NotMapped]
public int age { set; get; }
}
The Entity Framework doesn’t map the age
property.
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;}
}
[NotMapped]
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.
Comments