On the server side of my Silverlight solution, I have 2 projects.
I have a entity with FirstName and LastName properties on it. I want to add a FullName property that will be available from the Silverlight client side.
I have added the property:
namespace Server.DAL.Model
{
public partial class Contact
{
public string FullName
{
get
{
return string.Format("{0} {1}", this.FirstName, this.LastName);
}
}
}
}
When tested from the server side, this new property is present and working correctly. The property is NOT present on the Silverlight client side. I tried adding a metadata class with the Include
attribute but since string is a primitive type, I get the following error on compilation:
The property 'FullName' in entity type 'Contact' cannot be marked with the IncludeAttribute because 'String' is not a valid entity type. Entity types cannot be a primitive type or a simple type like string or Guid.
How can I make this property available to the Silverlight client?
You should put the code you have shared into a file called Contact.shared.cs
. The WCF RIA tooling takes this code exactly and creates a file in the Silverlight project with that code. The client-side code then has access to this member and a duplication of the code compiled in the server project.
Here is more information on shared code in the MSDN docs.
Add [DataMember] to your FullName property. Here are some instructions on adding methods/properties to ComplexTypes. They might apply to entities as well. Maybe using a buddy class, I haven't tried this for entities.
namespace Server.DAL.Model
{
public partial class Contact
{
[DataMember]
public string FullName
{
get
{
return string.Format("{0} {1}", this.FirstName, this.LastName);
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With