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

标签 c# azure azure-functions

创建使用 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/

相关文章:

c# - 如何使用任务并行库管理任务列表

java - 如何编写读取 MongoDB 数据库的 Maven Java Azure 函数?

c# - Azure 函数 V2 中的延迟消息 : The lock supplied is invalid

c# - 将安全 token 从一个依赖方委托(delegate)给另一个依赖方

c# - 0x81020014一个或多个字段类型未正确安装。进入列表设置页面删除这些字段

c# - 如何在 F# 中实现 C# 接口(interface)?

amazon-web-services - 使用相同代码库管理多个静态网站的解决方案

azure - 有没有办法在 Azure 数据工厂中使用 cURL 命令?

azure - 与ntp时钟同步

typescript - Azure函数: Can't figure out which ctor to call