Inject data annotation attributes to ViewModel
I am looking for solution to inject data annotation attributes to ViewModels in MVC. The idea is decorate the ViewModel class with Related Entity and the edmx file path and then read the Edmx file and the entity metat data information. Once entity meta data identified iterate through the properties of the view model, locate the matching entity attribute then decorate the view model with RequiredAttribute, StringLengthAttribute etc based on entity information.
Is it possible to use the t4 templates, since I have to read teh existing .cs file created by the user, modify and Save it.
How can i achieve this? Pls advice.