How to retain the data annotations or class during modify a table in the database


In database-first approach since there is an existing database., The entity classes are automatically created by edmx model.:

If we use [MetadataType(typeof(ConceptMetadataSource))] to attach a MetadataSource file which contains all the data annotations like [HiddenInput(DisplayValue = false)] or [Display(Name = "Title")]. The data annotations will be wiped out each time the entity classes are regenerated as the code will be regenerated once we modify a table in the database

Solution:
All you have to do is create another partial class and use Metadatatype attribute
Create a metadata class in models as below…
 
Create a Partial class for the metadata in models as below…
The new partial class can be created in a different folder

Comments

Popular posts from this blog

Interview Questions

AJAX CONTROL