How to add Computed Properties in WCF Ria Services on client

 

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.

ComputedPropertyCode

Hope you would find this useful. Awaiting your valuable feedback.

Cheers

Advertisements

2 thoughts on “How to add Computed Properties in WCF Ria Services on client

  1. This design is spectacular! You certainly know how to keep a reader entertained.
    Between your wit and your videos, I was almost
    moved to start my own blog (well, almost…HaHa!
    ) Great job. I really loved what you had to say, and more than that, how you presented it.

    Too cool!

  2. excellent publish, very informative. I’m wondering why the other specialists of this sector don’t realize this.
    You should continue your writing. I’m sure, you’ve a great readers’ base already!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s