Reputation: 46222
say I have the following code:
Truck truck = new Truck();
truck.id = '12323'
return view(truck);
Note that the Entity Truck has a number of fields associated with it such as color, Note, etc.
For Note, I like to add an annotation for the maxlength.
How do I go about adding and annotation. I know this is usually done in a class but in this case, I do not have a class as I am getting Truck directly from entity framework.
Upvotes: 0
Views: 205
Reputation: 470
You will want to make a partial class (aka buddy class) for your entity class and give it a MetadataType attribute. Check out this example with validation attributes. Specifically the section labeled Using Data Annotation Validators with the Entity Framework.
Upvotes: 1