Question

I'm trying to figure out how to create additional "calculated" properties that are exposed in a Silverlight client for a given Entity type. My solution structure is as follows (Simplified):

Namespace "Data Access", Class Lib, that holds my EDMX Namespace "Web" Web app that hosts the silverlight application as well as the Domain Service that projects over the EDMX (So it have a reference to the "Data Access" project.) Namespace "SLApp", the Silverlight App

One of my entities is Person (very simplified):

public partial class Person
{
   public string FirstName {get; set;}
   public string LastName {get; set;}
}

I want to have a "helper"/"calculated" property called FullName that simply puts the first and the last names together. In the past this was easy; create my own public partial class Person class and add the property/logic and then I can just use it as as normal property. But the RIA Domain Service does not seems to expose that property, so I can't use it on the client. If the EDMX was in the Web application I could use the .Shared.cs file and have it included in the SL app (I guess) but I don't want my EDMX in the web app (feels dirty :) )

I'm using the MVVM pattern so I could just create the Property on the ViewModel class, but seems like I'd have to duplicate that logic a number of times (any ViewModel that I need the FullName property on). I tried creating an extension method for the Person Object in the SL App called FullName, but apparently you can't bind to extension methods.

I'm new to Silverlight this is my first "real" application so maybe I'm just missing something very simple... I hope I am. Any help would be great.

Thank you!

Was it helpful?

Solution

Have you added [DataMember] Attribute to your calculated property?

[DataMember]
public string FullName
{
    get { return string.Format("{0} (1)", this.FirstName, this.LastName); }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top