I have a table in Azure Table Storage that I need to keep as a replica of a local SQL table. Adding/updating rows from the local table is simple enough but it is slightly more complicated to find rows that have been removed from the local table and therefore need to be removed from Azure Table Storage.

The ideal solution would be to keep a separate list of the rows that have been removed from the local table so they can then be deleted from Azure Table Storage but as that is not possible in this case I need to fetch all the entities from Azure Table Storage (productEntitiesToCheck) and check if they exist in the SQL table accessed via EntityFramework.

public List<ProductEntity> GetRemovedProductEntities(List<ProductEntity> productEntitiesToCheck)
{
	var removedEntities = from product in productEntitiesToCheck
						  where !_productContext.Products
							.Select(x => x.ToProductEntity())
							.Where(x => x.PartitionKey == product.PartitionKey
								&& x.RowKey == product.RowKey).Any()
						  select product;

	return removedEntities.ToList();
}

This method then provides a list of entities to be deleted from Azure Table Storage, it’s fine as long as both tables remain small as they should in my case but is probably not a good solution for trying to keep larger tables synchronized.


Leave a Reply

Your email address will not be published. Required fields are marked *