Friday 25 September 2015

Add a non Database field to the Model using Data Annotations

Sometime we may need to add a new column to our model but do not want to reflect that in the database. Especially in the code first development , we do not want to migrate that particular field to the database.

One way of achieving this is using a ViewModel. For some reason, if we really want to add this our Model class we can easily use the NotMapped Data annotation attribute as follows. Most of the time this could be a calculated column.

 
[NotMapped]
public decimal AccountBalance{get;set;}


No comments:

Post a Comment