0

i have a class the sales and product, which have the same declaration of object, these two class is auto generated by the server, all i want is set the annotation of them so that it can be reusable all the time, how can i set the MetadataType of this two into one,

From Sales

public partial class Sales
{
  public string Currency { get; set;}
}

From Product

public partial class Product
{
  public string Currency { get; set;}
}


namespace Validation.Access
{
    [MetadataType(typeof(TransferModuleValidation))]

    public partial class Product { }

    public partial class TransferModuleValidation
    {
        [MaxLength(3, ErrorMessage = "Must be less than or 3 characters")]
        public string Currency { get; set; 
    }
}

how can i set Sales in that example? do i have to inherit class (Product) to Sales?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
vaj90
  • 1,803
  • 3
  • 17
  • 17
  • check this this out , i already answered this question here http://stackoverflow.com/a/24757520/3050647 – elia07 Jul 15 '14 at 12:08

1 Answers1

1

Add the MetadataType to the other class...

namespace Validation.Access
{
    [MetadataType(typeof(TransferModuleValidation))]
    public partial class Sales { }

    [MetadataType(typeof(TransferModuleValidation))]
    public partial class Product { }

    public partial class TransferModuleValidation
    {
        [MaxLength(3, ErrorMessage = "Must be less than or 3 characters")]
        public string Currency { get; set; 
    }
}
Erik Philips
  • 53,428
  • 11
  • 128
  • 150