Skip to content

Instantly share code, notes, and snippets.

@MrMikeFloyd
Last active February 22, 2018 14:35
Show Gist options
  • Save MrMikeFloyd/16d93f0bace0bd1229f6b7767c96569c to your computer and use it in GitHub Desktop.
Save MrMikeFloyd/16d93f0bace0bd1229f6b7767c96569c to your computer and use it in GitHub Desktop.
Minimal C# Azure Function with an inbound table storage binding, resulting in "Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'System.Linq.IQueryable`1[test.TableRow]'". Created on macOS High Sierra with Visual Studio Code 1.19.3 and .NET Core 2.0.5
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=xxxxxxx;AccountKey=xxxxxxxxxxxxxx",
"AzureWebJobsDashboard": ""
}
}
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;
using System.Linq;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Net.Http;
using System.Net;
namespace test
{
public class TableRow : TableEntity
{
public Int32 valueX { get; set; }
public Int32 valueY { get; set; }
public Int32 valueZ { get; set; }
}
public static class read_from_tabstorage
{
[FunctionName("read_from_tabstorage")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequest req,
[Table("tabstoragetbl1", "")] IQueryable<TableRow> tRows,
TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
var row = tRows.FirstOrDefault();
if(row != null)
{
log.Info($"Data received: {row.valueX}");
}
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.6" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
@MrMikeFloyd
Copy link
Author

According to this issue, this is behaviour by design as support for IQueryable was dropped for v2 functions (reference). Therefore, CloudTable remains an option when binding to TableStorage in Azure v2 functions.

@MrMikeFloyd
Copy link
Author

Minimal working example for CloudTables posted here. This seems to be the way to go for v2 functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment