.NET RIA Services: Get your metadata from anywhere!

While the feedback on .NET RIA Services has been great, many people have commented on the way we store metadata as custom attributes on “buddy” classes of entities. 

For example, in my Mix demo to get automatic validation like this:



I had to provide metadata on my entity class on the server like this:



This is very cool and I believe works just fine in a lot of scenarios.  But sometimes you want to pull metadata from another source.  For example from a database or from calling a web service or by looking in an external metadata file. 

So with the .NET RIA Services May Preview we added a neat little sample that shows how to build your own metadata provider and a specific implementation that works with an external metadata file.  I’d expect you can pick up this sample and pretty easily update it to pull the metadata from your database or any other data source whenever the client XAP file is built.    

For example, this validation form…


Is driven from this xml..   Again, notice that this is just a sample, and you can define your own format. 

 <Metadata xmlns="http://schemas.microsoft.com/riaservices/metadata/2009">
   <MetaType Type="DomainModel.Product">
     <MetaProperty Name="ProductCode">
       <MetaAttribute Type="Key"/>
       <MetaAttribute Type="Required"/>
       <MetaAttribute Type="CustomValidation">
         <Argument Type="Type" Value="TestDomainValidator"/>
         <Argument Type="string" Value="ValidateProductCode"/>
     <MetaProperty Name="Name">
       <MetaAttribute Type="StringLength">
         <Argument Type="int" Value="50"/>
         <Property Name="MinimumLength" Value="10"/>


Check out the full sample or just the doc file explaining it and see the many other great .NET RIA Services based samples.