You can use the MetadataTypeAttribute
for this as documented on MSDN.
From the documentation but for completeness (a little altered to seal the metadata inside the class):
If you have an entity Customer
with a Title
property, you would define the property again in the metadata class
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
[MetadataType(typeof(Customer.CustomerMetaData))]
public partial class Customer
{
class CustomerMetaData
{
// Apply RequiredAttribute
[Required(ErrorMessage = "Title is required.")]
public string Title;
}
}