EnGen.OhData.Client 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package EnGen.OhData.Client --version 1.2.0
                    
NuGet\Install-Package EnGen.OhData.Client -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EnGen.OhData.Client" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EnGen.OhData.Client" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="EnGen.OhData.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EnGen.OhData.Client --version 1.2.0
                    
#r "nuget: EnGen.OhData.Client, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EnGen.OhData.Client@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EnGen.OhData.Client&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=EnGen.OhData.Client&version=1.2.0
                    
Install as a Cake Tool

<img src="assets/icon.svg" alt="OhData logo" width="110" align="right"/>

OhData

Convention-based OData 4.0 server and typed client for ASP.NET Core. Define a profile class, assign handler delegates, and get a spec-faithful OData API - no controllers required (see docs/spec-compliance.md for exactly what's covered). Consume it from .NET with a fluent, LINQ-native client.

Getting Started

Install the server package:

dotnet add package EnGen.OhData.AspNetCore

Install the client package:

dotnet add package EnGen.OhData.Client

Packages

Package NuGet What it does
EnGen.OhData.AspNetCore NuGet EntitySetProfile<TKey,TModel> base class, DI registration, endpoint factory, minimal API routes. Includes AddOhDataVersion / MapOhDataVersion versioning helpers and ODataEntitySetProfile<TKey,TModel> for full OData pushdown control.
EnGen.OhData.Client NuGet Typed .NET client. Fluent builder with LINQ-based $filter, $select, $expand, $orderby, and pagination.
EnGen.OhData.AspNetCore.Swashbuckle NuGet Optional Swashbuckle (Swagger) integration: OhDataSwaggerOperationFilter documents the OData query parameters on OhData endpoints.
EnGen.OhData.AspNetCore.OpenApi NuGet Optional Microsoft.AspNetCore.OpenApi (built-in AddOpenApi) integration: OhDataOpenApiOperationTransformer, same documentation as the Swashbuckle filter.
EnGen.OhData.AspNetCore.NSwag NuGet Optional NSwag integration: OhDataNSwagOperationProcessor, same documentation as the Swashbuckle filter.

Server quick start

// 1. Define your entity
public class Product
{
    public int Id { get; set; }
    public string Name { get; set; } = "";
    public decimal Price { get; set; }
}

// 2. Create a profile - assign only the handlers you need
public class ProductProfile : EntitySetProfile<int, Product>
{
    public ProductProfile(AppDbContext db) : base(x => x.Id)
    {
        FilterEnabled  = true;
        OrderByEnabled = true;
        CountEnabled   = true;
        SelectEnabled  = true;

        // IQueryable path: $filter/$orderby/$skip/$top push down to SQL via EF Core
        GetQueryable = (_) => Task.FromResult(db.Products.AsQueryable());
        GetById      = (id, ct) => db.Products.FindAsync(id, ct).AsTask();
        Post         = (p, ct) => { db.Products.Add(p); return db.SaveChangesAsync(ct).ContinueWith(_ => (Product?)p, ct); };
        Put          = (id, p, ct) => { db.Products.Update(p); return db.SaveChangesAsync(ct).ContinueWith(_ => p, ct); };
        Patch        = (id, delta, ct) => { var e = db.Products.Find(id); return Task.FromResult(e is null ? null : delta.Patch(e)); };
        Delete       = (id, ct) => { /* remove by id */ return Task.FromResult(true); };
    }
}

// 3. Register in Program.cs
builder.Services.AddOhData(o => o
    .WithPrefix("/odata")
    .AddProfile<ProductProfile>()                              // list profiles explicitly
    // ...or scan assemblies for every EntitySetProfile they contain:
    .AddProfilesFromAssembly(Assembly.GetExecutingAssembly())  // by assembly instance
    .AddProfilesFromAssemblyOf<ProductProfile>());             // by marker type

// 4. Map endpoints after app.Build()
app.MapOhData();

This produces:

Method Route Handler
GET /odata Service document
GET /odata/$metadata CSDL (EDM)
GET /odata/Products GetQueryable - supports $filter, $orderby, $skip, $top, $select, $count
GET /odata/Products/$count filtered row count
GET /odata/Products({key}) GetById
GET /odata/Products({key})/Name individual property (OData envelope) - rides GetById
GET /odata/Products({key})/Name/$value raw property value (text/plain)
PUT/PATCH /odata/Products({key})/Name set an individual property ({"value":...}) - rides Patch
DELETE /odata/Products({key})/Name set an individual property to null - rides Patch
POST /odata/Products Post
PUT /odata/Products({key}) Put
PATCH /odata/Products({key}) Patch
DELETE /odata/Products({key}) Delete

Only routes with a handler assigned are registered. Unassigned handlers produce no route.

OpenAPI / Swagger documentation

Each OpenAPI stack has an optional companion package that documents the OData query parameters ($filter, $orderby, $top, $skip, $select, $expand, $count, $search) on OhData endpoints, driven by each entity set's capability flags. Install the one matching your stack and register one line — the core package has no dependency on any OpenAPI stack:

Your stack Package Registration
Microsoft.AspNetCore.OpenApi (built-in AddOpenApi) EnGen.OhData.AspNetCore.OpenApi builder.Services.AddOpenApi(o => o.AddOperationTransformer<OhDataOpenApiOperationTransformer>());
Swashbuckle EnGen.OhData.AspNetCore.Swashbuckle builder.Services.AddSwaggerGen(c => c.OperationFilter<OhDataSwaggerOperationFilter>());
NSwag EnGen.OhData.AspNetCore.NSwag builder.Services.AddOpenApiDocument(s => s.OperationProcessors.Add(new OhDataNSwagOperationProcessor()));

See docs/openapi.md, docs/nswag.md, and docs/versioning.md (Swashbuckle multi-doc setup) for details.

Beyond the basics

The rest of the surface rides other profile declarations - navigation properties (HasMany/HasOptional/HasRequired), UseETag, and BindFunction/BindAction - rather than the plain CRUD handlers above:

Method Route Registered by
GET /odata/Orders({key})/Lines HasMany/HasOptional/HasRequired with a getAll/get/batchGetAll/batchGet delegate
GET /odata/Orders({key})/Lines/$count same, for collection navigations
POST /odata/Orders({key})/Lines HasMany with a post delegate - creates a related entity
GET/POST/PUT/DELETE /odata/Orders({key})/Lines/$ref HasMany/HasOptional with addRef/setRef/removeRef
GET /odata/Products/{FunctionName} BindFunction (collection-bound)
POST /odata/Products/{ActionName} BindAction (collection-bound)
GET /odata/Products({key})/{FunctionName} BindEntityFunction
POST /odata/Products({key})/{ActionName} BindEntityAction

See docs/navigation-routing.md, docs/property-access.md, docs/deep-insert.md, and docs/bound-operations.md for the full details behind each row.


Client quick start

// Setup - inject via IHttpClientFactory or create directly
var client = new OhDataClient("https://api.example.com/odata");

// Query with LINQ-style filter, ordering, and pagination
var page = await client.For<Product>()
    .Filter(x => x.Price > 10 && x.Name.StartsWith("W"))
    .OrderBy(x => x.Name)
    .Top(20)
    .Skip(0)
    .ToPageAsync();     // returns ODataPage<Product> with Items, TotalCount, NextLink

// Traverse all pages automatically via IAsyncEnumerable - follows @odata.nextLink
await foreach (Product p in client.For<Product>().Filter(x => x.Price > 0).ToAsyncEnumerable())
{
    Console.WriteLine(p.Name);
}

// Get a single entity - returns null on 404
Product? p = await client.For<Product>().Key(42).GetAsync();

// Mutate
Product created = (await client.For<Product>().InsertAsync(new Product { Name = "Cog", Price = 4.99m }))!;
var updated = await client.For<Product>().Key(created.Id)
    .PutAsync(new Product { Id = created.Id, Name = created.Name, Price = 5.49m });
await client.For<Product>().Key(42).PatchAsync(new { Price = 3.99m });
await client.For<Product>().Key(42).DeleteAsync();

With IHttpClientFactory:

// Registration
builder.Services.AddHttpClient<OhDataClient>(c => c.BaseAddress = new Uri("https://api.example.com/odata/"));
builder.Services.AddTransient(sp => new OhDataClient(sp.GetRequiredService<HttpClient>()));

// Injection
public class MyService(OhDataClient client) { ... }

Performance

OhData's minimal-API pipeline was benchmarked head-to-head against Microsoft.AspNetCore.OData's ODataController + [EnableQuery] pipeline over the full HTTP round-trip (routing → OData query-option processing → handler → serialization), same dataset, same requests, correctness verified before every run. OhData won all 11 scenarios:

Scenario OhData Microsoft.AspNetCore.OData Speedup Alloc ratio
GetAll page (100) 763 µs 2,821 µs 3.7× 6.3×
$filter 1,778 µs 3,393 µs 1.9× 6.0×
$orderby 968 µs 2,949 µs 3.0× 5.4×
$select 878 µs 1,858 µs 2.1× 1.3×
$top + $skip 1,262 µs 2,061 µs 1.6× 4.6×
$count=true (+$filter) 2,831 µs 4,740 µs 1.7× 5.4×
GetById 37 µs 112 µs 3.0× 3.0×
POST 51 µs 286 µs 5.6× 7.7×
PUT 57 µs 281 µs 4.9× 7.7×
PATCH 53 µs 325 µs 6.2× 7.1×
DELETE 16 µs 24 µs 1.5× 1.3×

The biggest gaps are on writes (POST/PUT/PATCH, ~5-6× — MS OData's OData-JSON formatters and EDM-bound serialization dominate there) and full-page reads (~3-3.7×). "Alloc ratio" is how many times more memory the MS OData pipeline allocates per request. BenchmarkDotNet over in-process TestServer hosts, identical 1,000-entity dataset and byte-identical requests on both sides, with a correctness gate run before measurement; see src/OhData.Server.Benchmarks/docs/server-comparison-report.md for the full methodology, raw output, and known asymmetries between the two pipelines.

Battle-testing

1,100 automated tests protect the framework end to end: 778 in OhData.AspNetCore.Tests (server routing, query options, navigation, ETags, authorization, malformed-payload hardening), 267 in OhData.Client.Tests, 30 in OhData.MicrosoftODataClient.Tests (compatibility against the official Microsoft.OData.Client), and 25 across the OpenAPI-integration suites (OhData.AspNetCore.OpenApi.Tests, OhData.AspNetCore.NSwag.Tests). Run them yourself with the commands in CLAUDE.md.


Documentation

Topic Guide
Query options ($filter, $orderby, $select, $expand, $count, $search) docs/query-options.md
Navigation property routing, $ref, and POST-to-navigation docs/navigation-routing.md
Individual property access, reads/writes, and /$value docs/property-access.md
Deep insert (nested related entities in POST) docs/deep-insert.md
Bound functions and actions docs/bound-operations.md
ETags and optimistic concurrency docs/etags.md
Authorization docs/authorization.md
API versioning docs/versioning.md
OpenAPI (built-in AddOpenApi) integration docs/openapi.md
NSwag integration docs/nswag.md
Client guide docs/client.md
OData 4.0 spec compliance docs/spec-compliance.md
Framework architecture docs/architecture.md
Migrating from Microsoft.AspNetCore.OData docs/migrating-from-microsoft-odata.md
Deployment (Dockerfile, Render) docs/deployment.md
Releasing to NuGet docs/releasing.md
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.7.0 1,462 9/1/2026
1.6.0 192 8/28/2026
1.5.0 778 7/22/2026
1.4.0 775 7/19/2026
1.3.0 359 7/18/2026
1.2.0 344 7/17/2026
1.1.0 389 7/17/2026
1.0.0 138 7/17/2026