-
-
Notifications
You must be signed in to change notification settings - Fork 10
OData controllers in memory
anton-martyniuk edited this page Sep 2, 2022
·
1 revision
Modern generic OData controllers use Modern generic repositories to perform OData queries.
To use In Memory OData Controller install the Modern.Controllers.DataStore.InMemory.OData.DependencyInjection
Nuget package and register it within Modern builder in DI:
builder.Services
.AddModern()
.AddInMemoryODataControllers(options =>
{
options.AddController<AirplaneDbo, long>();
});
Specify the type of dto entity model and primary key.
OData Controller requires one of modern repositories to be registered.\
Also register OData in the DI:
builder.Services.AddControllers(options =>
{
})
//..
.AddOData(opt =>
{
// Adjust settings as appropriate
opt.AddRouteComponents("api/odata", GetEdmModel());
opt.Select().Filter().Count().SkipToken().OrderBy().Expand().SetMaxTop(1000);
opt.TimeZone = TimeZoneInfo.Utc;
});
IEdmModel GetEdmModel()
{
// Adjust settings as appropriate
var builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
// Register your OData models here. Name of the EntitySet should correspond to the name of OData controller
builder.EntitySet<AirplaneDbo>("airplanes");
builder.EntityType<AirplaneDbo>();
return builder.GetEdmModel();
}