The code to fetch the data is not optimized

Jan 20, 2012 at 10:32 AM
Edited Jan 20, 2012 at 10:39 AM


I was looking at the source code for fetching the data and found that you're querying the data on "Timestamp" attribute of the entity.

/// <summary>
		/// Retrieves a collection of entities
		/// </summary>
		/// <typeparam name="TEntity">type of entity to retrieve</typeparam>
		/// <param name="tableName">name of the table</param>
		/// <param name="from">from date and time (inclusive)</param>
		/// <param name="to">end date and time (exclusive)</param>
		/// <param name="maxResult">maximum number of items to return</param>
		/// <returns>collection of entities</returns>
		public IEnumerable<TEntity> Retrieve<TEntity>(string tableName, DateTime from, DateTime to, int maxResult) where TEntity : TableServiceEntity
			return context.CreateQuery<TEntity>(tableName)
					.Where(w => w.Timestamp >= from)
					.Where(w => w.Timestamp < to)

Please note that this will result in full table scan. As long as your tables are small, this will not make much of a difference but as the table grows bigger, your query would become highly inefficient. I would recommend that instead of querying it on Timestamp attribute, please query on "PartitionKey" attribute.