I have an azure function for getting Mappings from a azure cosmos db document. However, it fails when trying to run a query within a query.
private static string GetKey(IEnumerable<Server> servers, int serverId)
=> servers.Where(s => s.ServerId == serverId).ToList().First().Key;
public static IEnumerable<Mapping> GetMappings(DocumentClient documentClient)
=> GetSitesDocumentQuery(documentClient)
.SelectMany(site => site.Terminals
.Select(terminal => new Mapping
{
Key = GetKey(site.Servers, terminal.ServerId),
// [...]
})
)
.ToList();
This fails with the following error message:
System.Private.CoreLib: Exception while executing function:
ProcessMessage. System.Private.CoreLib: One or more errors occurred.
(Method 'GetKey' is not supported., Windows/10.0.19042 documentdb-netcore-sdk/2.12.0).
Microsoft.Azure.DocumentDB.Core: Method 'GetKey' is not supported., Windows/10.0.19042 documentdb-netcore-sdk/2.12.0.
They're both members of the same class.
If I inline the query
public static IEnumerable<Mapping> GetMappings(DocumentClient documentClient)
=> GetSitesDocumentQuery(documentClient)
.SelectMany(site => site.Terminals
.Select(terminal => new Mapping
{
Key = site.Servers.Where(s => s.ServerId == serverId).AsEnumerable().First().Key,
// [...]
})
)
.ToList();
I get the same error message except now it claims First() is not supported.