azure函数应用程序中的LINQ子查询返回错误消息



我有一个azure函数,用于从azure cosmos db文档中获取映射。但是,尝试在查询中运行查询时会失败。

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

此操作失败,并显示以下错误消息:

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.

他们都是同一个班的成员。

如果我内联查询

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

我收到了同样的错误消息,只是现在它声称First()不受支持。

如果你这样做,它会起作用吗。AsEnumerable((或。前的ToList((。选择许多(..(?

最新更新