我正在从Azure表存储中检索数据并将其存储在IEnumerable中,但我不知道如何将此IEnumerable<T>
转换为IReliableDictionary<string, Store>
,以便我可以将此存储数据保存到州政府服务经理。
var storesRepo = await StateManager.GetOrAddAsync<IReliableDictionary<long, Store>>("");
那么如何将此IEnumerable<Store>
插入storesRepo
?
商店类:
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>
其中key是商店名称。
答案 0 :(得分:0)
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();
}