OData in .NET Core
State of the Union
Rainer Stropek | software architects | @rstropek
Introduction
Agenda, Material
Rainer Stropek
MVP for Azure and Developer Technologies
Microsoft Regional Director
Passionate programmer, entrepreneur,
teacher, dancer
rainer@software-architects.at
@rstropek
https://rainerstropek.me


Agenda, Material
- Why OData?
- OData Fundamentals
- OData and .NET Core
- Server
- Client

Why?
What's the Problem?
/customers
/customers/ALFKI
List of all
customers
Details of
ALFKI
...
/customers
/customers/ALFKI
List of all
customers
Details of
ALFKI
List sorted
by country
/customersByCountry
Only new
customers
/newCustomers
/newCustomersByCountry
...
/customers
/customers/ALFKI
List of all
customers
Details of
ALFKI
List sorted
by country
/customersByCountry
Only new
customers
/newCustomers
/newCustomersByCountry
...
Sorting, filtering, etc.
/customers
/customers/ALFKI
List of all
customers
Details of
ALFKI
List sorted
by country
/customersByCountry
Only new
customers
/newCustomers
/newCustomersByCountry
...
Sorting, filtering, etc.
- Data access protocol for the web
- Similar to SQL
- Works with HTTP
- Platform-neutral
- Standardization to enable generic clients
- Metadata
- Data encoding
- Read and write data
Enter: OData
Enter: OData
- ISO/IEC approved, OASIS standard
- https://www.odata.org/
- Current version: 4.01
- RESTful design principles
- Unlike GraphQL
- Platform agnostic, vendor-neutral
- Primarily driven by Microsoft and SAP
- Powerful protocol, therefore hard without framework
- Server-side practically bound to .NET
OData Protocol
https://api.myserver.com/odata/$metadata
https://api.myserver.com/odata/Customers?
$filter=CustomerID eq 15&
$top=10&
$select=FirstName,LastNameNot Just Basic Queries...
# Return all Categories containing more than two products whose price is greater than 5.00.
http://host/service/Categories?$filter=Products/$count($filter=Price gt 5.00) gt 2
# Return all Orders that have any Items with a Quantity greater than 100
http://host/service/Orders?$filter=Items/any(d:d/Quantity gt 100)
# Return customers along with their orders that shipped to the same city as the customer's address
http://host/service/Customers?$expand=Orders($filter=$it/Address/City eq ShipTo/City)- Not as flexible as SQL
- Predefined navigation over navigation properties
-
Demo
- Query open OData services using HTTP client (source)
- XOData
- Consume OData in Power BI (Query)
- Access Microsoft Graph using OData
($select, $filter on calendar)
Let's Start Coding...
OData Server with .NET Core
- Integrated in ASP.NET Core
- NuGet package Microsoft.AspNetCore.OData
- New version 7.3.0, compat with .NET Core 3.1
- Announcement
- ASP.NET Core Endpoint Routing not supported yet
- Docs
- Recently moved to docs.microsoft.com
- Note: ASP.NET Web API content also relevant for ASP.NET Core
-
Demo
- OData Fundamentals in .NET Core 3.1
- Sources
OData with Entity Framework
- EF Core is a good foundation for OData services
- Note: Not a prerequisite!
- OData uses IQueryable for queries
- POST, PUT/PATCH, DELETE for writing
- Similar to regular ASP.NET Core
- Not covered here
URL
Parser
OData AST
IQueryable
C# Expression Tree
SQL
EF Core
OData Client
-
Simple OData Client
- Demo
- Issuing HTTP requests manually
- C# HttpClient
- JavaScript frameworks (e.g. Angular)
- JavaScript libraries
- E.g. Breeze.js
- UI libraries with OData support
- E.g. Telerik KendoUI
Drawbacks
- Implementing OData service without EF is rather complicated
- Demo
- Not fully compatible with ASP.NET Core 3.1
- Endpoint routing is still missing
- Many tools are legacy and not maintained
- E.g. client code generator, RESTier
Summary
Summary
- OData is great if you need a CRUD service
- OData gives client a lot of control
- No need to do client-side filtering, sorting, etc.
- Platform-independent and - theoretically - vendor-neutral
- Documentation could be enhanced
- Some pieces smell a little bit like legacy 😉
- Basic .NET Core 3.1 support exists
Thank you for attending!
OData in .NET Core
By Rainer Stropek
OData in .NET Core
- 1,072