gpt4 book ai didi

c# - Microsoft.Azure.WebJobs.Host.Tables.TableExtension+TableToIQueryableConverter`1[TElement ]' violates the constraint of type ' TElement'

转载 作者:行者123 更新时间:2023-12-03 04:50:45 25 4
gpt4 key购买 nike

创建使用 Azure 表存储作为输入绑定(bind)的 Azure 函数并尝试检索多个实体而不是单个实体时,出现以下错误:

Error:
Function ($ScheduleTrigger) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.myTimerTrigger'. Microsoft.Azure.WebJobs.Host: GenericArguments[0], 'Submission#0+Task', on Microsoft.Azure.WebJobs.Host.Tables.TableExtension+TableToIQueryableConverter`1[ TElement]' violates the constraint of type 'TElement'. mscorlib: GenericArguments[0], 'Submission#0+Task', on 'Microsoft.Azure.WebJobs.Host.Tables.TableExtension+TableToIQueryableConverter`1 [TElement]' violates the constraint of type parameter 'TElement'.
Session Id: f4a00564b4864fb3a131557dd45924c7

Timestamp: 2017-09-05T07:48:09.738Z

在本例中,我用于 C# 计时器触发器的代码如下:

using System;

public class Task
{
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public DateTime Timestamp { get; set; }
public string Name { get; set; }
}

public static async Task Run(TimerInfo myTimer, IQueryable<Task> inputTable, TraceWriter log)
{
foreach (var task in inputTable) {
log.Info($"Processing task '{task.Name}' at: {DateTime.Now}");
}
log.Info($"Timer trigger executed at: {DateTime.Now}");
}

最佳答案

我自己找到了上述问题的答案,但由于错误消息没有很快给我答案,我想我应该自己发布并回答这个问题。

导致该错误的原因是我用于实体的模型不是从 EntityTable 派生的,如下所述:https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table

只需将上面的代码示例更改为以下内容即可修复错误:

using System;

public class MyInput : TableEntity
{
public string Name { get; set; }
}

public static async Task Run(TimerInfo myTimer, IQueryable<MyInput> inputTable, TraceWriter log)
{
foreach (var item in inputTable) {
log.Info($"Processing item '{item.Name}' at: {DateTime.Now}");
}
log.Info($"Timer trigger executed at: {DateTime.Now}");
}

关于c# - Microsoft.Azure.WebJobs.Host.Tables.TableExtension+TableToIQueryableConverter`1[TElement ]' violates the constraint of type ' TElement',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46050629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com