MetadataType without applying attribute on target class?

149 Views Asked by At

Is it possible to apply a MetadataType class to a target class without applying a MetadataType attribute directly to that class?

Say I've got this class:

public class Animal
{
    public int AnimalId { get; set; }
    public string AnimalType { get; set; }
}

And this other class:

public class AnimalMetadata
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int AnimalId { get; set; }

    [Required]
    [MaxLength(100, ErrorMessage = "Animal Type must not exceed 100 characters")]
    [Display(Name = "Taxonomical Classification")]
    public string AnimalType { get; set; }
}

I'd like to apply the AnimalMetadata class as the MetadataType for Animal. But say I don't own the Animal class such that I can apply an attribute on it, or it resides in an assembly that cannot be introduced to AnimalMetadata and all of its referential dependencies. Can I still use AnimalMetadata as a MetadataType for Animal? If so, how?

0

There are 0 best solutions below