Enhancements that make adoption of Azure Function Apps easier for .NET developers.
This package adds binding extensions to handle OData queries on HTTP requests.
The underlying OData support is provided by the ASP.NET Core OData package and only supports querying IQueryable data sources.
Note: EF Core has several limitations with OData queries.
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddOData(builder =>
{
builder.EntitySet<Department>("Departments");
builder.EntitySet<Product>("Products");
});
}
}
HttpTrigger Function
public class FnGetProductsHttp
{
private readonly DbContext _context;
public FnGetProductsHttp(DbContext context)
=> _context = context ?? throw new ArgumentNullException(nameof(context));
[EnableQuery(MaxTop = 100, AllowedQueryOptions = AllowedQueryOptions.All)]
[FunctionName(nameof(FnGetProductsHttp))]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "products")] HttpRequest req,
ODataQueryOptions<Product> odata)
{
var results = await odata.ApplyTo(_context.Products).Cast<dynamic>().ToListAsync().ConfigureAwait(false);
return new OkObjectResult(results);
}
}