I seem to understand the reason behind taking help of MetadataTypeAttribute
to Add Validation to the Model in case of Database First as we want to avoid the changes
I don't know why you are trying to employ a Database first technique to a more complete, say, Code first since you can create ViewModels to meet your purpose. Also not all the data annotations are supported in Entity Framework.
ViewBag
, ViewData
or something else to pass
additional information to the viewIf you want to add attributes to existing properties in a class (partially) :
This may work or be ignored by the EF, test it:
public partial class YourModelClass
{
public string YourProperty{get;set;}
}
//Your Partial Class
[MetadataType(typeof(YourModelClassMetaData))]
public partial class YourModelClass
{
}
//The class that adds your attributes
public class YourModelClassMetaData
{
[Required]
public object YourProperty{get;set;}
}