0

I am retrieving data from Azure Table Storage and storing them in IEnumerable, but I don't know how to convert this IEnumerable<T> into IReliableDictionary<string, Store>, so that I can save this store data into state manager of stateful service.

var storesRepo = await StateManager.GetOrAddAsync<IReliableDictionary<long, Store>>(""); 

So how can I insert this IEnumerable<Store> into storesRepo?

Store Class:

    public class Store : TableEntity
    {
    public string Name { get; set; }
    public double Longitude { get; set; }
    public double Latitude { get; set; }
    public string Address { get; set; }
    public double Distance { get; set; }
    public string Email { get; set; }
    public string City { get; set; }
    }


    ReliableDictionary<string, Store>

where key is store name.

Rumpi Guha
  • 118
  • 1
  • 1
  • 7
  • Hi there, *not able to* does not give us any clue on what exactly is going wrong (do you get any errors for example?) And can you tell what you are trying to accomplish? Some code will help as well. – Peter Bons May 06 '18 at 08:53
  • Hi, I m retrieving some data from Azure table Storage as IEnumerable . But I don't know how to convert this IEnumerable into IReliableDictionary, so that I can save this store data into state manager of stateful service. var storesRepo = await StateManager.GetOrAddAsync>(""); So how can I insert this IEnumerable into storeRepo – Rumpi Guha May 06 '18 at 09:24
  • 1
    Please add the code to the question by editing it next time, makes it many times more readable. I did it for this time. – Peter Bons May 06 '18 at 10:29
  • 1
    In your setup, what would be the unique key of the ReliableDictionary, would that be a property of `Store`? How does the class `Store` look like? – Peter Bons May 06 '18 at 10:30

1 Answers1

0
  • Create a dictionary, enumerate over all stores in the collection, add them one by one, inside a transaction.
  • Make sure the set of stores doesn't get too large to avoid a long running transactions & locks.
  • Make sure to think about partitioning first
  • Add retry support.
  • Apply best practices from here.

meta code below:

var storesRepo = await StateManager.GetOrAddAsync<IReliableDictionary<string, Store>>("someName");    
IEnumerable<Store> stores = await GetFromTableStorage();
using (ITransaction tx = base.StateManager.CreateTransaction()) 
{
   foreach(var store in stores)
   {
      await storesRepo.AddAsync(tx, store.Name, store, cancellationToken);
   }
   await tx.CommitAsync();
}
LoekD
  • 11,402
  • 17
  • 27