Convert IReliableDictionary to IList

I have an IReliableDictionary and you need to take elements in a dictionary and move them to IList in order to return from my reliable service.

It seems I can not do .ToList of any type, so I am sure that I am not mistaken.

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(); ???

   ...
}

Any ideas on how to take items from a dictionary and put them on a list?

+1
source share
2 answers

IReliableDictionary (just like IDictionary) is IEnumerable from key value pairs, so you can go like this:

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
source

IReliableDictionary<K,V>implements IEnumerable<KeyValuePair<K, V>>, so you can do ToList.

Maybe the namespace is being imported.

0
source

All Articles