OData .NET Libraries
repository·main·Indexed 20 days ago
https://github.com/odata/odata.netCore implementation of the Open Data Protocol (OData) for the .NET ecosystem. Provides libraries for URI parsing, request/response payload handling, Entity Data Model (EDM) construction, and a LINQ-enabled client for consuming OData services. Includes ODataV4 libraries (ODataLib, EdmLib, Microsoft.Spatial, and OData Client for .NET) and maintenance libraries for OData v1-3.
What's inside odata.net
- The OData .NET Libraries implement core OData protocol functionalities on the .NET platform. They provide tools for URI parsing, reading and writing request/response payloads, building Entity Data Models (EDM), and a client for consuming OData services. These libraries are the foundation for building OData services using WebApi or RESTier.
Overview of Microsoft.OData.Core
mainThe
Microsoft.OData.Corelibrary is a fundamental component of the OData .NET libraries. It provides the necessary classes to serialize, deserialize, and validate OData JSON payloads. It specifically supports ODatav4andv4.01versions.Key functionality includes reading and writing OData messages (requests and responses) in OData JSON format, primarily through the
ODataMessageReaderandODataMessageWriterclasses.What the OData Client WASM Sample demonstrates
mainThis sample application provides an interactive UI to test the asynchronous APIs of
Microsoft.OData.Clientwithin a WebAssembly environment. It demonstrates the following categories of operations:Entity Operations
SaveChangesAsync: Adding entities.SaveChangesAsync(with batch options): Adding entities using batching.BulkUpdateAsync: Updating multiple entities.DeepInsertAsync: Inserting complex entity graphs.
Query Operations
GetValueAsync: Retrieving single entities.ExecuteAsync: Executing filtered queries.ExecuteBatchAsync: Executing batch requests.
Function & Query Operations
ExecuteAsync: Calling OData functions.GetAllPagesAsync: Retrieving all pages of paged results.
Navigation & Loading
LoadPropertyAsync: Loading navigation properties.LoadPropertyAsync(with continuation tokens): Loading navigation properties using tokens.LoadPropertyAllPagesAsync: Loading all pages of related entities.
Stream Operations
GetReadStreamAsync: Reading media entity streams.GetReadStreamAsync(named streams): Reading specific named streams.
Action Operations
GetValueAsync: Executing OData actions that return scalar values.
What is Microsoft.OData.Edm and how does it work?
mainThe
Microsoft.OData.Edmlibrary provides APIs to build, parse, and validate anEntity Data Model (EDM)that conforms to the OData protocol. It acts as the schema layer that describes the data types and functionality exposed by an OData service.Key components include:
IEdmModel: The base interface used across OData libraries to retrieve information about exposed types.EdmModel: A class implementingIEdmModelused to manually create a model/schema in memory.CsdlReaderandCsdlWriter: Classes used for reading/parsing and writing schema files in CSDL (Common Schema Definition Language) formats, such asXMLorJSON.EdmLib: The common name for this library.
Prepare Visual Studio Profiler reports for comparison
mainThe Results Comparer tool cannot read
.diagsessionfiles directly. You must manually export the data from the Visual Studio Profiler into text files.Steps to export:
- Open the desired view in Visual Studio (e.g.,
AllocationsorFunctions). - Select the rows: Click the first row, hold
Shift, and click the last row to select the entire table. - Right-click and select Copy.
- Paste the data into a new text file and save it.
- Repeat this process for both your base report and your diff report.
Note for Function Allocations: Ensure you expand the namespaces you are interested in before copying, otherwise, the methods within those namespaces will not be included in the text file.
- Open the desired view in Visual Studio (e.g.,
Get support and community help for OData .NET
mainIf you encounter issues or have questions regarding the OData .NET libraries, use the following channels:
- Issues: Report bugs or issues on GitHub issues.
- Questions: Ask technical questions on Stack Overflow.
- Feedback: Send feedback to odatafeedback@microsoft.com.
- Updates: Follow the Team blog or odata.org/blog.
Install Microsoft.OData.Client via NuGet
mainYou can install the
Microsoft.OData.Clientpackage to consume OData services (supporting ODatav4andv4.01) from your .NET applications using either the .NET CLI or the NuGet Package Manager Console.# Using .NET CLI dotnet add package Microsoft.OData.Client # Using NuGet Package Manager Console Install-Package Microsoft.OData.ClientRun load tests and collect traces
mainLoad Tests
Load tests measure request round-trips to evaluate how libraries handle concurrent requests. Use
loadtests.ymlto run these scenarios. You can specify the writer implementation using thewritervariable.Example (Serialization Comparisons):
crank --config loadtests.yml --config lab-windows --scenario SerializationComparisons --application.options.counterProviders System.Runtime --variable writer=ODataMessageWriterCollecting Traces
To collect native trace files (e.g.,
.etlfiles via PerfView on Windows) for analysis, use the--[job].collect trueoption, where[job]is the name of the job in your.ymlconfig.Example (Collecting traces for the 'application' job):
crank --config loadtests.yml --config lab-windows --scenario SerializationComparisons --variable writer=ODataMessageWriter --application.collect truecrank --config loadtests.yml --config lab-windows --scenario SerializationComparisons --application.options.counterProviders System.Runtime --variable writer=ODataMessageWriter crank --config loadtests.yml --config lab-windows --scenario SerializationComparisons --variable writer=ODataMessageWriter --application.collect trueGenerate strongly-typed client code with OData Connected Service
mainTo interact with an OData service using strongly-typed models, use the
OData Connected Serviceextension in Visual Studio. This automates the creation of the client code required to map service entities to .NET classes.- Install the extension: Search for
OData Connected ServiceinExtensions > Manage Extensionsin Visual Studio, or download it from the Visual Studio Marketplace. - Add to project: Right-click your project in Solution Explorer, select Add > Connected Service, choose OData Connected Service, and follow the configuration wizard for your specific service URI.
- Install the extension: Search for
Build and test OData .NET using Visual Studio
mainTo build and test the project in Visual Studio, open the
OData.slnshortcut at the root level. This solution contains the product source and relevant unit tests.There are two primary solution files:
OData.sln: Contains product source for .NET Framework 4.5, .NET Standard 1.1 (except OData Client), and .NET Standard 2.0. Unit tests are built for .NET Framework 4.5.2, .NET Core 1.1, 2.1, and 3.1.OData.E2E.sln: Contains product source for .NET Framework 4.5 and an exhaustive list of unit, E2E, and regression tests. Use this for full code verification.
Note: When running tests within
OData.E2E.sln, you must open Visual Studio as an Administrator to allow test services to start correctly.Run the Server and Client separately
mainIf you need to run the Server and Client projects independently, follow these steps:
- Run the Server project (
Microsoft.OData.Client.Wasm.Sample.Server). - Run the Client project (
Microsoft.OData.Client.Wasm.Sample.Client) separately. - Update the Client's
serviceUriconfiguration to point to the URL where the Server is hosted.
- Run the Server project (
Use Results Comparer to find performance regressions
mainThe Results Comparer is a tool designed to compare performance reports to identify regressions or improvements. It is useful for comparing historical results (before/after changes), results across different operating systems (Windows vs Ubuntu), different CPU architectures (x64 vs ARM64), or different target frameworks (.NET Core 3.1 vs 5.0).
To use the tool, you must provide a baseline (
--base) and a diff (--diff). You can optionally specify the report type, a statistical threshold, a noise threshold, or a specific metric to compare.cd src/ResultsComparer dotnet run -- --type bdn --base "C:\results\BenchmarkDotNetReportBefore.json" --diff "C:\results\BenchmarkDotNetReportAfter.json" --threshold 1%