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.

Answers


Need Your Help

mmap causes stack corruption, kernel involved?

c linux glibc mmap

We are getting segfaults with this code:

Regular expression to remove special characters in JSTL tags

regex jsp replace jstl

I am working on a Spring application and in JSPX page I need to dynamically load some values from properties page and set them as dropdown using options tag. I need to use same text for options va...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.