简体   繁体   中英

Forcing a string field to DateTime in WCF query with Azure Table Storage

So, a quick overview of what I'm doing: We're currently storing events to Azure Table storage from a Node.js cloud service using the "azure-storage" npm module. We're storing our own timestamps for these events in storage (as opposed to using the Azure defined one).

Now, we have coded a generic storage handler script that for the moment just stores all values as strings. To save refactoring this script, I was hoping there would be a way to tweak the query instead.

So, my question is, is it possible to query by datetime where the stored value is not actually a datetime field and instead a string?

My original query included the following:

.where( "_timestamp ge datetime'?'", timestamp );

In the above code I need to somehow have the query treat _timestamp as a datetime instead of a string...

Would something like the following work, or what's the best way to do it?

.where( "datetime _timestamp ge datetime'?'", timestamp );

AFAIK, if the attribute type is String in an Azure Table, you can't convert that to DateTime . Thus you won't be able to use .where( "_timestamp ge datetime'?'", timestamp );

If you're storing your _timestamp in yyyy-MM-ddTHH:mm:ssZ format, then you could simply do a string based query like

.where( "_timestamp ge '?'", timestamp );

and that should work just fine other than the fact that this query is going to do a full table scan and will not be an optimized query. However if you're storing in some other format, you may get different results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM