我有一个IReliableDictionary,需要把字典中的项目移到IList中,然后从我可靠的服务中返回。
似乎我做不了。任何类型的列表,所以我确定我接近它错了。
public async Task<IList<CustomerOrderItem>> GetOrdersAsync()
{
IReliableDictionary<CustomerOrderItemId, CustomerOrderItem> orderItems =
await this.StateManager.GetOrAddAsync<IReliableDictionary<CustomerOrderItemId, CustomerOrderItem>>(CustomerOrderItemDictionaryName);
Dictionary<KeyValuePair<CustomerOrderItemId, CustomerOrderItem>, KeyValuePair<CustomerOrderItemId, CustomerOrderItem>> items = orderItems.ToDictionary(v => v);
IList<CustomerOrderItem> list = orderItems.ToList(); ???
...
}
关于如何从字典中取出项目并将它们放入列表的任何想法?
答案 0 :(得分:1)
IReliableDictionary(就像一个IDictionary)是IEnumerable的键值对,所以你可以这样:
public async Task<IList<CustomerOrderItem>> GetOrdersAsync()
{
IReliableDictionary<CustomerOrderItemId, CustomerOrderItem> orderItems =
await this.StateManager.GetOrAddAsync<IReliableDictionary<CustomerOrderItemId, CustomerOrderItem>>(CustomerOrderItemDictionaryName);
var list = orderItems.Select(kvp => kvp.Value).ToList();
return list;
}
答案 1 :(得分:0)
IReliableDictionary<K,V>
实施IEnumerable<KeyValuePair<K, V>>
,因此您可以执行ToList
。
也许确保导入名称空间。