Microsoft.Azure.WebJobs.Host.Tables.TableExtension + TableToIQueryableConverter`1 [TElement]'违反了类型'TElement'的约束 [英] Microsoft.Azure.WebJobs.Host.Tables.TableExtension+TableToIQueryableConverter`1[TElement]' violates the constraint of type 'TElement'
问题描述
创建使用Azure表存储作为输入绑定的Azure函数并尝试检索多个实体而不是单个实体时,会出现以下错误:
When creating an Azure Function that uses Azure Table Storage as an input binding and trying to retrieve multiple entities instead of just a single enntity I get the following error:
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#计时器触发器的代码如下:
The code I use for the, in this case, C# timer trigger is as follows:
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}");
}
推荐答案
我自己也找到了上述答案,但是由于错误消息并没有迅速为我提供答案,所以我认为我会发布并回答问问自己.
I've found the answer to the above myself, but since the error message didn't get me an answer quickly I figured I'd post and answer the question myself.
引起该错误的原因是,我用于实体的模型不是从EntityTable派生的,如以下所述:
The error is caused because the model I used for my entity does not derive from EntityTable as described here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table
只需将上面的代码示例更改为以下内容,即可修复该错误:
Simply changing the code sample above to the following will fix the error:
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}");
}
这篇关于Microsoft.Azure.WebJobs.Host.Tables.TableExtension + TableToIQueryableConverter`1 [TElement]'违反了类型'TElement'的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!