.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.

Comments (25)

  1. Tobbe says:

    I just heard about RIA Services and printed out the May documentation. RIA will be my summer project. Keep on inventing good stuff =)

  2. What's New says:

    While the feedback on .NET RIA Services has been great, many people have commented on the way we store

  3. Mitch Cain says:

    This is great when I know ahead of time (design time) what the rules are for a particular entity, but what if they change at runtime? For instance, setting a certain value on a City makes the Country required? You only know the value of city at runtime.  

  4. Thank you for submitting this cool story – Trackback from DotNetShoutout

  5. If you are looking to follow this series, be sure to subscribe to my RSS feed at http://feeds.jasongaylord

  6. ASPInsiders says:

    If you are looking to follow this series, be sure to subscribe to my RSS feed at http://feeds.jasongaylord.com/JasonNGaylord

  7. Thomas Hansen says:

    This issue was brought up at MIX, and it’s cool to see that the comments from the industry were listened to. RIA DS will definetly be more flexible by integrating the metadata into the pipeline. Looking forward to the release, keep up the good work! 🙂

  8. Dean Nolan says:

    This seems like it could be really useful.

    I don’t like my code cluttered with lots of meta data and it should be easier to change if it’s in a database.

  9. 9eFish says:

    9efish.感谢你的文章 – Trackback from 9eFish

  10. Noam says:

    Looks like there is an issue with the XmlMetadataProvider. The metadata is not attached to properties that come from a base class. So in code like this (yes, I know its silly, but its to explain my point):

       public partial class ProductBase


           public string ModelNumber {get; set;}

           public string Name { get; set; }

           public int AvailableQuantity { get; set; }


       public partial class Product : ProductBase



           public int ProductID { get; set; }

           public string Description { get; set; }

           public decimal UnitCost { get; set; }


    and my metadata XML file is:

    <Metadata xmlns="http://schemas.microsoft.com/riaservices/metadata/2009"&gt;

     <MetaType Type="MyApp.DataModel.Product">

       <MetaProperty Name="AvailableQuantity">

         <MetaAttribute Type="Required"/>


       <MetaProperty Name="UnitCost">

         <MetaAttribute Type="Exclude"/>




    Metadata is attached to properties of the product class (the UnitCost prop), but not to properties from the base class.

  11. Great stuff.

    Steve Sanderson shows how to use DataAnnotations with his xVal library (on codeplex) for ASP.NET MVC.

    One thing I like about this library is that you can use a ‘IRule’ to create rules programmatically.

    So to the above question – I think it would be very cool to be able to load a set of validations based on some criteria and using a strategy pattern ‘attach’ a set of validation rules to a domain object.

    ie. the state of Ohio might have a different validation than the state of Kentucky – you could have your domain objects loosely coupled from the set of rules for each, loading them in to the domain object based on the state you are in and then apply those rules.

    To me this is just a matter of exposing the underlying rules interfaces – again, see xVal.  Maybe this provider here does this as well

    Great example though – I assume from above, you could keep different xml validation sets for different scenarios and load those dynamically as well.

  12. I have previously written about the UNPLUGGED road trip that Mike , Nathan and I have been on. I also

  13. 逆援助 says:


  14. 出会い says:


  15. 救援部 says:


  16. メル友 says:


  17. 出会い says:


  18. 家出 says:


  19. 当サイトは、みんなの「玉の輿度」をチェックする性格診断のサイトです。ホントのあなたをズバリ分析しちゃいます!玉の輿度チェッカーの診断結果には、期待以上の意外な結果があるかも

  20. 毎月10万円を最低ラインとする謝礼を得て、セレブ女性に癒しを与える仕事があります。無料登録した後はメールアプローチを待つだけでもOK、あなたもセレブラブで欲求を満たしあう関係を作ってみませんか

  21. よーやくプロフ持ちになれました。私の事気になった方がいましたら気軽にメールください。恋バナとか好きなんでよろしくでぇす。zuttozuttoissyodayo@docomo.ne.jp

  22. 女性会員様増加につき、当サイトの出張ホストが不足中です。女性の自宅やホテルに出向き、欲望を満たすお手伝いをしてくれる男性アルバイトをただいま募集していますので、興味のある方はTOPページから無料登録をお願いいたします

  23. 家出 says:


  24. あなたのモテ度数を診断できる、モテる度チェッカー!日頃モテモテでリア充のあなたもそうでないヒキニートの貴方も隠されたモテスキルを測定して今以上にモッテモテになること間違いなし

Skip to main content