Azure 函数应用程序中的 LINQ 子查询 returns 错误消息
LINQ subquery in azure function app returns error message
我有一个 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.
他们都是同一个class的成员。
如果我内联查询
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()
不受支持。
如果在 .SelectMany(..) 之前执行 .AsEnumerable() 或 .ToList() 是否有效?
我有一个 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.
他们都是同一个class的成员。
如果我内联查询
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()
不受支持。
如果在 .SelectMany(..) 之前执行 .AsEnumerable() 或 .ToList() 是否有效?