1 year ago
#69304

LorneCash
ServiceStack TimeSpan Serialization can't be Cast by SQL to Time(7)
When TimeSpan
properties are serialized they end up looking like this: -PT10M
, PT30S
, or PT6H
. My real problem is that in MSSQL I can't use the Cast
function to get them to a Time so if there's an easy way to do that I'm open to that solution however I believe the easiest thing will be to figure out how to get ServiceStack to change it's serialization behavior and instead serialize them like this -0:10:00
, 0:00:30
, or 6:00:00
respectively.
The way I'm serializing them now is to just call MyObject.ToJson()
.
Is changing the serialization the way to go and if so how can I do that with ServiceStack?
UPDATE
Please ignore the negative time values I'm aware SQL's Time
type can only hold positive values. This actually doesn't affect what I'm trying to do at the moment. I have other fields where the time can sometimes be negative so I included them in my question as an example but it's not really relevent to my question.
After some more testing I can confirm that values stored like this like this -0:10:00
, 0:00:30
, or 6:00:00
deserialize fine. Still, is there a way to force them to serialize to this more easily readable value like this?
Here's almost the same question for Newtonsoft: https://stackoverflow.com/questions/39876232
c#
sql-server
servicestack
timespan
0 Answers
Your Answer