Read the other posts in this series:
In the previous blog posts listed above, I showed how Telerik’s new LINQ
implementation works with WCF
RIA Services. I showed how to build your own Domain Service as well as build custom
query methods. In this post I will show how to build a metadata class. (Note: future
versions of the OpenAccess LINQ Implementation will produce the metadata class for
The WCF RIA Services metadata class is a separate class from the DomainService that
contains information about the entities. In this class you can write custom validation
logic, set attributes of the properties of the entities or indicate whether the property
is to be generated on the client or not.
To create this class, create a new class in Visual Studio and name it: YourDomainSeriveClassName.metadata.cs.
For example, our DomainService is DomainService1, so the metadata class is: DomainService1.metadata.cs.
Erase everything in the class and then replace it with the following, using the proper
namespace in your project:
//the MetadataTypeAttribute identifies CustomersMetadata as the class
//that carries additional metadata for the Customers class.
//Metadata classes are not meant to be instantiated.
Let’s do a quick example on the CompanyName property, we will set it to required,
set an error message to be displayed if the field is not entered as well as set a
length of 32. This is done with two attributes:
"CompanyName is Required!!"
Now when you perform databinding, RIA Services will enforce these rules for you on
the client. For example, if try to edit our data in the application built in Part
II, RIA Services automatically adds validation for us and passes on the error
message we specified in the attribute. (Note you have to add an UpdateCustomer method
to your DomainService1 class to enable editing.)
Stephen Forte sits on the board of several start-ups including Triton Works. Stephen is also the Microsoft Regional Director for the NY Metro region and speaks regularly at industry conferences around the world. He has written several books on application and database development including Programming SQL Server 2008 (MS Press).
Copyright © 2016, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.