Skip to content
This repository has been archived by the owner on Jan 30, 2022. It is now read-only.

Enhancements that make adoption of Azure Function Apps easier for .NET developers.

License

Notifications You must be signed in to change notification settings

smokedlinq-archive/AzureFunctions.Extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AzureFunctions.Extensions

Build SonarCloud Status

Enhancements that make adoption of Azure Function Apps easier for .NET developers.

AzureFunctions.Extensions.Http

NuGet NuGet

AzureFunctions.Extensions.OData

NuGet NuGet

This package adds binding extensions to handle OData queries on HTTP requests.

Features

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.

Example usage

Setup

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);
    }
}