How to add Computed Properties in WCF Ria Services on client

Posted by in Silverlight category on for Intermediate level | Points: 250 | Views : 9831 red flag

In this post I teach you how can you add a computed property in WCF ria services

Customers have become very demanding these days, but thanks to the technology that we can satisfy them. I met one of our clients for the new project. The project was complex in the sense that it involved lot of calculations. The prime requirement of the client was that the end user must immediately see the output of the calculations once all the required input is provided by them. My first choice for any LOB apps is Silverlight 4 + WCF Ria services. So the big question was that how can I get this done. 

After doing a bit research I found out that it was pretty straight forward with WCF Ria Services framework. So here we go I will outline the solution with sample scenario. The scenario is pretty simple. We have customer Entity mapped to Customer table in the database. Following are its columns.

  • FirstName
  • LastName
  • DateOfBirth
Now here is the twist we need to calculate the Age of the customer. As this property needs to be computed we don’t have it in our database but this should be calculated after user enters date of birth. So to accomplish this follow the steps mentioned below
  1. Add a new partial class of the same name in your client project. Please ensure that this class namespace is same as your Domain Service namespace.
  2. This class must be inherited from the Entity class available in System.ServiceModel.DomainServices.Client namespace.
  3. Add a read only property “Age” of integer type. Write your age calculation logic in the get block of this property.
  4. Raise the property event when the DateOfBirth property is changed.

Hope you would find this useful. Awaiting your valuable feedback. Cheers
Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Muhammad Afzal Qureshi
Member Level: Bronze
Member Status: Member
Member Since: 8/4/2009 10:58:17 PM
Country: India
Hello Everyone Myself Muhammad Afzal , aka GoldyTech. Thats my pen name. I reside in India and work as a solution Architect on .NET platform. I hope you must have enjoyed reading my blog. Please leave your comments or suggestions good or bad and help me to improve

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)