I am developing a solution with Silverlight RIA Services. One of the requirements is "push" notification to clients, which I am implementing using a blocking call to the server, that returns when an update is recieved. Trying to implement this using a generic structure, I've come to this data structure:
public class Change
{
public ObjectType Type { get; internal set; } // objecttype is an enum
public int ObjectKey { get; internal set; }
public string PropertyName { get; internal set; }
public object OldValue { get; internal set; }
public object NewValue { get; internal set; }
//key required for RIA Services
[Key]
public Guid ChangeGuid { get; private set; }
}
Apart from some obvious flaws in this design (this is just a test), the properties OldValue
and NewValue
are not visible on the client, due to their type of object. The values of these properties will always be an Entity Framework primitive.
Is there any way of getting OldValue
and NewValue
to the client without converting everything to strings?
Googling didnt get me very far due to the object
keyword cluttering up the search results.
Any general solution regarding my problem is appreciated.
If you serialise across WCF as "object" you cannot reintroduce other interfaces/types on the client side implicitly. You are effectively serialising them as string anyway.
The internal details about what sort of object "it really is" are not retained across serialisation.
How about one nullable member, per ObjectType enum value, and only set the one you need? This may add a small overhead to the data transferred but may be more manageable and will give you strongly typed objects.