Windows Azure Platform Developer Center > Microsoft Visual Studio 2010 Beta 2 Forums > Windows Azure > Azure Table Storage - How to query entities with a filter on non initialized fields.
Ask a questionAsk a question
 

AnswerAzure Table Storage - How to query entities with a filter on non initialized fields.

  • Friday, November 06, 2009 11:04 PMClement Lime Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hey Azure experts.

    If I understand well, azure table storage entities are similar to a Hashtable containing <string, object> pairs. Therefore when I add a new field 'LastActivityTimestamp' to my entity, all previously created entites will have null for that field.
    My question is how do I get all entities that have 'LastActivityTimestamp' == null ?

    I tried the following query but Azure returns "One of the request inputs is not valid." in the HTTP response :
    this.DataContext.Chatters.Where(chatter => chatter.LastActivityTimestamp == null || chatter.LastActivityTimestamp < minDateTime).AsEnumerable();

    If I do this query : this.DataContext.Chatters.Where(chatter => chatter.LastActivityTimestamp < minDateTime).AsEnumerable();
    then it returns only the entities that statisfy the filter AND have a non null value.

    Any help much appreciated.

Answers

  • Saturday, November 07, 2009 6:14 AMGaurav Mantri Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Clement,

    I don't think that is also not possible because even if you retrieve all entities, you will not get the desired attribute if it does not exist. One possible solution could be to get all entities and check if that particular attribute exists in your entity set or not. If that attribute does not exist in an entity, that would be the entity you want to know about.

    Hope this helps.

    Thanks

    Gaurav Mantri
    Cerebrata Software
    http://www.cerebrata.com/

All Replies

  • Saturday, November 07, 2009 5:21 AMGaurav Mantri Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Clement,

    You can't check if an element is null simply because if an element's value is null, it won't be stored in table storage (remember it's not a conventional table). Only exception to this is the PartitionKey, RowKey & TimeStamp elements.

    Hope this helps.

    Thanks

    Gaurav Mantri
    Cerebrata Software
    http://www.cerebrata.com/
  • Saturday, November 07, 2009 5:39 AMClement Lime Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Gaurav.

    So are you saying that the only way to retrieve entities for which the new field is not initialized to is retrieve all entities and then test the field from the client app ??
  • Saturday, November 07, 2009 6:14 AMGaurav Mantri Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Clement,

    I don't think that is also not possible because even if you retrieve all entities, you will not get the desired attribute if it does not exist. One possible solution could be to get all entities and check if that particular attribute exists in your entity set or not. If that attribute does not exist in an entity, that would be the entity you want to know about.

    Hope this helps.

    Thanks

    Gaurav Mantri
    Cerebrata Software
    http://www.cerebrata.com/