Skip to content

OData/AspNetCoreOData

Repository files navigation

ASP.NET Core OData 8.x


Component Build Status
ASP.NET Core OData Rolling Build status
ASP.NET Core OData Nightly Build status
.NET Foundation Release Build status

1. Introduction

Be noted: Switch to use "main" as default branch. 1/6/2022

This is the official ASP.NET Core OData repository. ASP.NET Core OData is a server side library built upon ODataLib and ASP.NET Core.

Blogs:

Documentation:

For comprehensive documentation, please refer to the following links:

Example:

  • ODataRoutingSample: ASP.NET Core OData sample project in this repo.

    • ~/$odata gives a static routing table page of the service

    • ~/swagger gives a swagger/openapi page

    • Append ~/$openapi to each route gives a raw openapi OData page, for example, ~/v1/$openapi

    Please go to sample folder see more samples.

Solution:

2. Basic Usage

Microsoft.AspNetCore.OData Package Installation

Using .NET CLI:

dotnet add package Microsoft.AspNetCore.OData

Using Package Manager:

Install-Package Microsoft.AspNetCore.OData

In the ASP.NET Core Web Application project, update your Startup.cs as below:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<BookStoreContext>(opt => opt.UseInMemoryDatabase("BookLists"));
        services.AddControllers().AddOData(opt => opt.AddRouteComponents("odata", GetEdmModel()));
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        // Send "~/$odata" to debug routing if enable the following middleware
        // app.UseODataRouteDebug();

        app.UseRouting();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }

    private static IEdmModel GetEdmModel()
    {
        // …
    }
}

If you work with Program.cs, update as below. Refer to the Getting Started Guide.

// using statements

var builder = WebApplication.CreateBuilder(args);

var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntityType<Order>();
modelBuilder.EntitySet<Customer>("Customers");

builder.Services.AddControllers().AddOData(
    options => options.Select().Filter().OrderBy().Expand().Count().SetMaxTop(null).AddRouteComponents(
        "odata",
        GetEdmModel()));

var app = builder.Build();

app.UseRouting();

app.MapControllers();

app.Run();

static IEdmModel GetEdmModel()
{
    // …
}

That's it.

3. Building, Testing, Debugging and Release

3.1 Building and Testing in Visual Studio

Visual Studio 2022 is required to build the source project in order to support the DateOnly and TimeOnly types, which were introduced in .NET 6.

3.2 One-click build and test script in command line

Coming soon.

3.3 Debug

The symbol package is uploaded to nuget symbol server.

It supports source link debug. Remember to check Enable Source Link support if you debug using Visual Studio.

3.4 Nightly Builds

The nightly build process will upload NuGet packages for ASP.NET Core OData to:

To connect to webapinightly feed, use this feed URL:

4. Documentation

5. Community

5.1 Contribution

Any contributions, feature requests, bugs and issues are welcome.

5.2 Reporting Security Issues

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) [email protected]. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter. You can also find these instructions in this repo's SECURITY.md.

5.3 Support

Code of Conduct

This project has adopted the .NET Foundation Contributor Covenant Code of Conduct. For more information see the Code of Conduct FAQ.

.NET Foundation

This project is supported by the .NET Foundation.

AspNetCoreOData is a Copyright of © .NET Foundation and other contributors. It is licensed under MIT License