[RIA Services] Use Shared class for metadatas

With
WCF RIA Services and DomainServices, the metadatas file is generated from
selected entities of the ADO.NET Entity Data Model. But if you want to add the “FullAddress”
property in the metadatas, this error appears:

“The associated metadata type for type ‘SharedInfos.Web.Customers’
contains the following unknown properties or fields: FullAddress. Please make
sure that the names of these members match the names of the properties on the
main type.”


Shared classes allow completing this metadatas with properties and/or
methods. This file has the .share.cs extension (or .shared.vb). Notice that the
namespace must be the same as the Web project.

namespace SharedInfos.Web
{
 
public partial class Customers
  {
    
public string FullAddress
     {
       get
       {
         
return Address + ” ” + PostalCode + ” ” + City;
       }
     }
  }
}


During the compilation, the file is duplicated from the server side to the client
side. And the new functionalities are both accessible from the client and the
server side.

 

Now the
new property “FullAddress” is  available :

These files with additional
methods make it, interesting to use CustomValidations in metadatas for example (to
be continued in a next post).

 

Leave a Reply

Your email address will not be published. Required fields are marked *