I am using MVC and entity framework. I started with code first design and I was applying attributes like [Required] and [Display] but how do I do this if I am using a model first? I created my database model already.
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, I’m sure that you have generated your classes from your Edmx (?). Then
Solution One
Generated classes are partial classes.
So you can add a new class file, with a partial class (same as the generated one), with a MetadataType attribute (class can be empty).
And in the class given in the MetadataType attribute, you can put the “generated class”‘s properties, with attributes.
Solution 2
Never use your Model classes, but ViewModel(s) (I suppose you know what it is, if no, you’ll find tons of info without too much efforts), and put attributes in these ViewModel classes.