How do I expose a TimeSpan through a WCF Data Service?
I am creating a WCF Data Service for my database of appointments.
I'm storing the appointment as a DateTime with a duration of type TimeSpan. When I attempt to access my data service, I get the following error:
"The server encountered an error processing the request. The exception message is 'The property 'Duration' on type 'Appointment' is of type 'Time' which is not a supported primitive type.'. See server logs for more details."
Any idea how I can represent a time duration and ha开发者_开发技巧ve it accessible through my WCF Data Service?
I would suggest exposing a new property for serialization (marked with the DataMemberAttribute
) that use the Ticks
property of your original timespan.
For example:
[DataMember("TheTimeSpanTicks")]
public long TheTimeSpanTicks
{
get { return TheTimeSpan.Ticks; }
set { TheTimeSpan = new TimeSpan(value); }
}
I'm not sure what the accessor requirements for serialization will be. Maybe you could use protected
instead of public
.
You could expose the duration as Ticks, TotalSeconds, or some other primitive that can be calc'ed to hours, minutes, etc?
精彩评论