如何从 IEnumerable<T> 上传 IReliable 字典中的数据
How to upload data in IReliable dictionary from IEnumerable<T>
我正在从 Azure Table 存储中检索数据并将它们存储在 IEnumerable 中,但我不知道如何将此 IEnumerable<T>
转换为 IReliableDictionary<string, Store>
,以便我可以保存这将数据存储到有状态服务的状态管理器中。
var storesRepo = await StateManager.GetOrAddAsync<IReliableDictionary<long, Store>>("");
那么我怎样才能将这个 IEnumerable<Store>
插入到 storesRepo
中呢?
商店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>
其中键是商店名称。
- 创建一个字典,枚举集合中的所有商店,一个一个地添加,在一个transaction.
中
- 确保存储集不会变得太大以避免长时间的 运行 事务和锁定。
- 一定要先考虑partitioning
- 添加重试支持。
- 应用 here 中的最佳实践。
元代码如下:
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();
}
我正在从 Azure Table 存储中检索数据并将它们存储在 IEnumerable 中,但我不知道如何将此 IEnumerable<T>
转换为 IReliableDictionary<string, Store>
,以便我可以保存这将数据存储到有状态服务的状态管理器中。
var storesRepo = await StateManager.GetOrAddAsync<IReliableDictionary<long, Store>>("");
那么我怎样才能将这个 IEnumerable<Store>
插入到 storesRepo
中呢?
商店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>
其中键是商店名称。
- 创建一个字典,枚举集合中的所有商店,一个一个地添加,在一个transaction. 中
- 确保存储集不会变得太大以避免长时间的 运行 事务和锁定。
- 一定要先考虑partitioning
- 添加重试支持。
- 应用 here 中的最佳实践。
元代码如下:
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();
}