6.4.0
This is a backport of the OData API Explorer extensions for ad hoc EDM intended for .NET 6.0 and .NET Core 3.1. Most people should move on to 7.0
.
Features
ASP.NET Core with OData
- Added support for ad hoc Model Bound Settings
- Add
ODataApiExplorerOptions.AdHocModelBuilder
which is used in the same way asODataApiVersioningOptions.ModelBuilder
- Examples:
- Add
Non-OData Model Bound Settings
Several OData query settings, such as the allowed properties, can only be configured using Model Bound settings. This information is annotated in the Entity Data Model (EDM). How do you configure this information if you're only using some of OData and don't have an EDM?
The OData API Explorer extensions already support using conventions, but it does not allow you to specify a convention which cannot be mapped to some combination of ODataQueryOptionSettings
or ODataValidationSettings
. ModelBoundSettings
is supported, but mapping custom conventions over it would largely be a duplication of what ODataModelBuilder
already does.
The new API Explorer support bridges this gap by creating ad hoc EDM instances on your behalf for the sole purpose of configuring Model Bound settings. This allows you to define configurations you couldn't otherwise without having to use an EDM. You have the choice to use attributes or the ODataModelBuilder
fluent API for conventions.
Consider the following:
[Filter( "author", "published" )] // ← model bound settings with attributes
public class Book
{
public string Id { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public int Published { get; set; }
}
The result of this configuration will show the $filter
query option and indicate only the author
and published
properties can be used. If you prefer not to use attributes, the convention-based API can be used as well:
AddODataApiExplorer(
options =>
options.AdHocModelBuilder.DefaultConfiguration = (builder, version, prefix) =>
builder.ComplexType<Book>().Filter( "author", "published" ) ) ;
The ad hoc EDM is only available during API exploration and is then discarded. It does not opt into any OData features.
Fixes
ASP.NET Core with OData
- Fixed empty EDM detection
Breaking Changes
None
Contributors
- @SamGuoMsft for pushing the backport to .NET 6.0 [LTS] (#928)