Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeSpan property in Azure Table Storage

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?

like image 530
Kai G Avatar asked Jul 06 '12 15:07

Kai G


1 Answers

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.

like image 140
JamieSee Avatar answered Oct 20 '22 05:10

JamieSee