Display DataAnnotation with MetadataType

Topics: Validation Application Block
May 28, 2012 at 3:24 PM

Hi!

I have my business classes decorated with the MetadataType attribute (Microsoft.Practices.EnterpriseLibrary.Validation.DataAnnotations) so that I can specify data annotations in separate classes. This works well, and I am able to validate and display error messages in my Silverlight client.

Now I wanted to take this further, and decorated the properties with annotations like [Display(Name=…, Description=…)]. I want this information to be used in <sdk:Label/> and the <sdk:DescriptionViewer/>. Is this possible with the p&p implementation of MetadataType?

I did not get this to work. I have provided a sample here http://sdrv.ms/MT9OqF showing that the “First name:” label is not displaying as expected.

Thank you / Michael

May 29, 2012 at 1:19 AM
Edited May 29, 2012 at 2:37 PM

The attribute (and infrastructure) for Microsoft.Practices.EnterpriseLibrary.Validation.DataAnnotations.MetadataTypeAttribute exists because Silverlight doesn't support (the useful) built-in MetadataTypeAttribute.  As the documentation indicates:

This attribute might be deprecated in the future in favor of a Silverlight built-in System.ComponentModel.DataAnnotations.MetatadataTypeAttribute. The current implementation allows a Silverlight application using Validation Application Block to take advantage of this feature which is available in the .NET Framework, and it can be useful for cross-tier validation scenarios.

Whether that will happen seems up in the air (at the very least!).  The MetadataTypeAttribute implementation is basically just a link between the two classes -- the key is for the framework to make use of this information to provide functionality.  The Enterprise Library 5.0 Integration Pack for Silverlight only provides functionality for validation.  

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com