OdataToEntity 2.2.0

Classes to serialize, deserialize OData JSON payloads. Supports OData v4 only. Enables construction of OData services via Entity Framework (Linq2Db) DataContext (without controller). Targets .NET Core with support for .NET 4.6.1

There is a newer version of this package available.
See the version list below for details.
Install-Package OdataToEntity -Version 2.2.0
dotnet add package OdataToEntity --version 2.2.0
<PackageReference Include="OdataToEntity" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OdataToEntity --version 2.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OdataToEntity, 2.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install OdataToEntity as a Cake Addin
#addin nuget:?package=OdataToEntity&version=2.2.0

// Install OdataToEntity as a Cake Tool
#tool nuget:?package=OdataToEntity&version=2.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

OdataToEntity

Wiki
Travis

OData .net core

This library provides a simple approach to creating OData service from ORM data context. This translates the OData query into an expression tree and passes it to the ORM framework. Supported ORM: Entity Framework 6, Entity Framework Core, Linq2Db

public sealed class OrderContext : DbContext
{
    public DbSet<Customer> Customers { get; set; }
    public DbSet<Order> Orders { get; set; }

    public IEnumerable<Order> GetOrders(int? id, String name, OrderStatus? status) => throw new NotImplementedException();
}

Build OData EdmModel

Buid from entity classes marked data annotation attribute, the general case for all providers

//Create adapter data access, where OrderContext your DbContext
var dataAdapter = new OeEfCoreDataAdapter<Model.OrderContext>();
//Build OData Edm Model
EdmModel edmModel = dataAdapter.BuildEdmModel();

Build from the Entity Framework Core where the data context uses the "Fluent API" (without using attributes)

//Create adapter data access, where OrderContext your DbContext
var dataAdapter = new OeEfCoreDataAdapter<Model.OrderContext>();
//Build OData Edm Model
EdmModel edmModel = dataAdapter.BuildEdmModelFromEfCoreModel();

Build from the Entity Framework 6 where the data context uses the "Fluent API" (without using attributes)

//Create adapter data access, where OrderEf6Context your DbContext
var dataAdapter = new OeEf6DataAdapter<OrderEf6Context>();
//Build OData Edm Model
EdmModel edmModel = dataAdapter.BuildEdmModelFromEf6Model();

Build from multiple data contexts

//Create referenced data adapter
var refDataAdapter = new OeEfCoreDataAdapter<Model.Order2Context>();
//Build referenced Edm Model
EdmModel refModel = refDataAdapter.BuildEdmModel();

//Create root data adapter
var rootDataAdapter = new OeEfCoreDataAdapter<Model.OrderContext>();
//Build root Edm Model
EdmModel rootModel = rootDataAdapter.BuildEdmModel(refModel);

Sample OData query

By default used cached queries parsed to expression tree, which on existing tests allows you to increase the performance up to three times. For disable this feature, you need pass in base constructor OeDataAdapter parameter new OeQueryCache(false). The query is parameterized (i.e. constant expressions are replaced with variables) except null value, therefore for best performance must use database null semantics. For Ef Core method UseRelationalNulls class RelationalDbContextOptionsBuilder<TBuilder, TExtension>, for Ef6 property UseDatabaseNullSemantics class DbContextConfiguration.

//Create adapter data access, where OrderContext your DbContext
var dataAdapter = new OeEfCoreDataAdapter<Model.OrderContext>();
//Create query parser
var parser = new OeParser(new Uri("http://dummy"), dataAdapter.BuildEdmModel());
//Query
var uri = new Uri("http://dummy/Orders?$select=Name");
//The result of the query
var response = new MemoryStream();
//Execute query
await parser.ExecuteGetAsync(uri, OeRequestHeaders.JsonDefault, response, CancellationToken.None);

OdataToEntity

Wiki
Travis

OData .net core

This library provides a simple approach to creating OData service from ORM data context. This translates the OData query into an expression tree and passes it to the ORM framework. Supported ORM: Entity Framework 6, Entity Framework Core, Linq2Db

public sealed class OrderContext : DbContext
{
    public DbSet<Customer> Customers { get; set; }
    public DbSet<Order> Orders { get; set; }

    public IEnumerable<Order> GetOrders(int? id, String name, OrderStatus? status) => throw new NotImplementedException();
}

Build OData EdmModel

Buid from entity classes marked data annotation attribute, the general case for all providers

//Create adapter data access, where OrderContext your DbContext
var dataAdapter = new OeEfCoreDataAdapter<Model.OrderContext>();
//Build OData Edm Model
EdmModel edmModel = dataAdapter.BuildEdmModel();

Build from the Entity Framework Core where the data context uses the "Fluent API" (without using attributes)

//Create adapter data access, where OrderContext your DbContext
var dataAdapter = new OeEfCoreDataAdapter<Model.OrderContext>();
//Build OData Edm Model
EdmModel edmModel = dataAdapter.BuildEdmModelFromEfCoreModel();

Build from the Entity Framework 6 where the data context uses the "Fluent API" (without using attributes)

//Create adapter data access, where OrderEf6Context your DbContext
var dataAdapter = new OeEf6DataAdapter<OrderEf6Context>();
//Build OData Edm Model
EdmModel edmModel = dataAdapter.BuildEdmModelFromEf6Model();

Build from multiple data contexts

//Create referenced data adapter
var refDataAdapter = new OeEfCoreDataAdapter<Model.Order2Context>();
//Build referenced Edm Model
EdmModel refModel = refDataAdapter.BuildEdmModel();

//Create root data adapter
var rootDataAdapter = new OeEfCoreDataAdapter<Model.OrderContext>();
//Build root Edm Model
EdmModel rootModel = rootDataAdapter.BuildEdmModel(refModel);

Sample OData query

By default used cached queries parsed to expression tree, which on existing tests allows you to increase the performance up to three times. For disable this feature, you need pass in base constructor OeDataAdapter parameter new OeQueryCache(false). The query is parameterized (i.e. constant expressions are replaced with variables) except null value, therefore for best performance must use database null semantics. For Ef Core method UseRelationalNulls class RelationalDbContextOptionsBuilder<TBuilder, TExtension>, for Ef6 property UseDatabaseNullSemantics class DbContextConfiguration.

//Create adapter data access, where OrderContext your DbContext
var dataAdapter = new OeEfCoreDataAdapter<Model.OrderContext>();
//Create query parser
var parser = new OeParser(new Uri("http://dummy"), dataAdapter.BuildEdmModel());
//Query
var uri = new Uri("http://dummy/Orders?$select=Name");
//The result of the query
var response = new MemoryStream();
//Execute query
await parser.ExecuteGetAsync(uri, OeRequestHeaders.JsonDefault, response, CancellationToken.None);

NuGet packages (6)

Showing the top 5 NuGet packages that depend on OdataToEntity:

Package Downloads
OdataToEntity.EfCore
Classes bridge from ODataToEntity to Entity Framework Core. Abstraction layer access to DataContext Entity Framework Core.
OdataToEntity.Ef6
Classes bridge from OdataToEntity to Entity Framework 6.3.0. Abstraction layer access to DataContext Entity Framework 6.3.0.
OdataToEntity.AspNetCore
Extension for easy create Asp Mvc .Net Core service
OdataToEntity.Linq2Db
Classes bridge from OdataToEntity to Linq2Db. Abstraction layer access to DataContext Entity Linq2Db
OdataToEntity.GraphQL
Translate and execute GraphQL query via OData

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.8.0 99 7/23/2021
2.7.0 175 3/7/2021
2.6.1 389 1/9/2021
2.6.0 341 11/13/2020
2.5.1 466 8/8/2020
2.5.0.3 785 5/26/2020
2.5.0.2 446 5/24/2020
2.5.0.1 453 2/29/2020
2.5.0 486 2/26/2020
2.4.0 715 9/28/2019
2.3.1 892 6/4/2019
2.3.0 644 5/2/2019
2.2.0 652 2/3/2019
2.1.0 626 12/2/2018
2.0.1 549 10/31/2018
2.0.0 683 8/18/2018
2.0.0-beta1 506 8/15/2018
2.0.0-beta 516 8/12/2018
1.6.2 1,031 7/17/2018
1.6.1 500 7/16/2018
1.6.0 667 7/15/2018
1.5.0 701 6/3/2018
1.4.1 697 4/1/2018
1.4.0 650 3/4/2018
1.3.0 1,860 11/5/2017
1.2.0 830 8/28/2017
1.1.1 678 8/1/2017
1.1.0 681 7/14/2017
1.0.0.1 867 11/23/2016
1.0.0 860 11/18/2016
Show less