As it is shortly described in the topic: How to move all DataAnnotations from model to MetaData model in order not to wipe it out when updating edmx?
In another words I would like to have data annotation secure and not get rid of with each update of edmx and I would have in dataannotation an option to check if all data annotations requirements are fulfiled (IsValid method) to use it in CanExecute method of RelayCommand.
I have a class as follows:
public partial class Customer : IDataErrorInfo
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public int ID{ get; set; }
[Required(ErrorMessage = "Field required")]
public string Name{ get; set; }
[Required(ErrorMessage = "Field required")]
public string LastName{ get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<tblKontrahent> tblKontrahent { get; set; }
#region Validation
public bool IsValid { get; set; }
public string Error { get { return null; } }
public string this[string columnName]
{
get
{
Validation();
return InputValidation<Customer >.Validate(this, columnName);
}
}
public ICollection<string> AllErrors()
{
return InputValidation<Customer >.Validate(this);
}
private void Validation()
{
ICollection<string> allErrors = AllErrors();
if (allErrors.Count == 0)
IsValid = true;
else
IsValid = false;
}
#endregion
#region Shallow copy
public Customer ShallowCopy()
{
return (Customer )this.MemberwiseClone();
}
#endregion
}
How to move it from Model to MetaDataModel with the annotations and IsValid function. It would be great if ShallowCopy method could be also moved.
Thank you VERY MUCH for any suggestions!.