IReliableDictionary does not contain a definition for Select

181 Views Asked by At

I am trying to convert Reliable dictionary object to IList or IEnumerable but I'm getting error for contactDetails.Select as

IReliableDictionary<int, ContactDetail> does not contain a definition for 'Select' and no accessible extension method 'Select'...

Below is code I am using

ReliableDictionary<int, ContactDetail> contactDetails = await _stateManager.GetOrAddAsync<IReliableDictionary<int, ContactDetail>>("contacts");
            
var contactDetailsList = contactDetails.Select(x => x.Value).ToList();
1

There are 1 best solutions below

0
On

You will need to use IReliableDictionary<TKey,TValue>.CreateEnumerableAsync to enumerate the dictionary:

https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicefabric.data.collections.ireliabledictionary-2.createenumerableasync?view=azure-dotnet

As you iterate over the enumerable, you can add each entry to a list. The reliable dictionary does not support LINQ.

There is a sample project (Voting Data) that uses this approach (look at the Get method):

https://github.com/microsoft/devops-project-samples/blob/cadeabb45a9726f98986e8e024518d42e5b6a49d/dotnet/aspnetcore/servicefabric/Application/VotingData/Controllers/VoteDataController.cs