MetadataSource - Support MetadataTypeAttribute


If the target object is decorated with the MetadataTypeAttribute the MetadataSource does not lookup the ValidationAttributes on the correct class.

MetadataTypeAttribute is used to specifiy a class that contains the DataAnnotations attributes. This useful when using generated classes such as in LinqToSQL.

Attached is a possible fix.

file attachments

Closed Sep 2, 2013 at 4:00 PM by amanek
Reporter confirmed that issue cannot be reproduced.


amanek wrote Sep 2, 2013 at 12:24 PM

I doubt that such issue exist. MetadataTypeAttribute is supported by MetaTable class which is responsible for retrieval of the validation attributes. When constructed through Create method MetaTable internal implementation uses AssociatedMetadataTypeTypeDescriptionProvider which takes care of the attributes discovery and even merging.

Can you try this sample? In my case it works as expected and returns 2 attributes:
MetadataSource source = new MetadataSource();
source.ObjectType = typeof (Foo);

var attributes = source.GetValidationAttributes("Bar");
Debug.Assert(attributes.Count() == 2);
public class Foo
    public string Bar { get; set; }

public class FooMetadata
    public string Bar { get; set; }
The only case that I can imagine and which can prevent this to work is custom implementation of TypeDescriptionProvider that exists and registered inside your project.

g_richards1 wrote Sep 2, 2013 at 1:32 PM

amanek, I can confirm after further testing that you are correct, it does pickup the DataAnnotations from the associated class.

Please close this issue.


wrote Sep 2, 2013 at 4:00 PM