Is there any way to get dataanotations for my models directly from my database?
I have a database with lot’s of data and tables, so i am generating my model with entity framework from database, so i get classes, but i want to know can entity framework or some other orm get properities and constrains directly from database and put them in classes as data anotation like [required] or [datatype(datatype.emailadress)]
Is there any way to get dataanotations for my models directly from my database?
Share
Yes. You can inherit the ModelMetadataProvider class:
I’m creating a project called Griffin.MvcContrib which is almost done and has a administration area where you can handle all localization (zero-code) for both models and validation messages.
By using it you can just implement the following interface to get support for your database:
Update
Where is not important. And you do not have to use DataAnnotation attributes on your models (the
[Display]attribute). I just inherit theDataAnnotationsModelMetadataProviderto be able to use the attributes.Example: