I have an entity with a TimeSpan
property I want to save in Azure Table Storage. When I attempt to save the entity I get the error:
Can't cast to unsupported type 'TimeSpan'
Is there some way to do an automatic conversion or some other way to support TimeSpan
?
I store the TimeSpan as ticks in an int or bigint field and convert that. You could also store it as a varchar. I prefer ticks because you can do math on it in the database if you need to and it makes range comparisons easier. If you're using Entity Framework, you can declare an unmapped property that gets and sets a TimeSpan from your database-friendly property.
Have a look at Entities in Azure Tables. Part of it describes how to exclude a property from Azure Table Storage, which should make what I proposed with EF workable for ATS as well.
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