Nate Pet
Nate Pet

Reputation: 46222

MVC Entity Framework Annotation

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

Answers (1)

Erica
Erica

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.

http://www.asp.net/mvc/tutorials/older-versions/models-(data)/validation-with-the-data-annotation-validators-cs

Upvotes: 1

Related Questions