Skip to content

alkondrashov/odata

Repository files navigation

OData

Commands

dotnet new webapi -o odata
dotnet add package Microsoft.EntityFrameworkCore.InMemory
dotnet add package Microsoft.AspNetCore.Odata

https://localhost:7005/WeatherForecast

https://localhost:7005/odata

https://localhost:7005/odata/Cars

https://localhost:7005/odata/Cars(2)

https://localhost:7005/odata/Cars?$filter=Price le 50

IEdmModel GetEdmModel()
{
    var builder = new ODataConventionModelBuilder();
    builder.EntitySet<Car>("Cars");
    return builder.GetEdmModel();
}
builder.Services.AddDbContext<ODataContext>(opt => opt.UseInMemoryDatabase("Cars"));
builder.Services.AddControllers().AddOData(opt => opt.AddRouteComponents("odata", GetEdmModel()));
public IActionResult Get()
{
    return Ok(_context.Cars);
}
[EnableQuery]
[EnableQuery]
public IActionResult Get(int key)
{
    return Ok(_context.Cars.FirstOrDefault(c => c.Id == key));
}
builder.Services.AddControllers().AddOData(opt => opt.AddRouteComponents("odata", GetEdmModel()).Filter().Select());

Resources

  1. https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint
  2. https://devblogs.microsoft.com/odata/asp-net-core-odata-now-available/
  3. https://devblogs.microsoft.com/odata/asp-net-odata-8-0-preview-for-net-5/
  4. https://referbruv.com/blog/posts/working-with-odata-integrating-an-existing-aspnet-core-3x-api

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages