OData .NET Libraries

repository·main·Indexed 20 days ago

https://github.com/odata/odata.net

Core 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.

Tokens
7.5K
Snippets
21
Records
38
Agent score
73%

What's inside odata.net

  1. Overview of OData .NET Libraries

    main
    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.
  2. Overview of Microsoft.OData.Core

    main

    The Microsoft.OData.Core library 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 OData v4 and v4.01 versions.

    Key functionality includes reading and writing OData messages (requests and responses) in OData JSON format, primarily through the ODataMessageReader and ODataMessageWriter classes.

  3. What the OData Client WASM Sample demonstrates

    main

    This sample application provides an interactive UI to test the asynchronous APIs of Microsoft.OData.Client within 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.
    • 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.
  4. What is Microsoft.OData.Edm and how does it work?

    main

    The Microsoft.OData.Edm library provides APIs to build, parse, and validate an Entity 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 implementing IEdmModel used to manually create a model/schema in memory.
    • CsdlReader and CsdlWriter: Classes used for reading/parsing and writing schema files in CSDL (Common Schema Definition Language) formats, such as XML or JSON.
    • EdmLib: The common name for this library.
  5. Prepare Visual Studio Profiler reports for comparison

    main

    The Results Comparer tool cannot read .diagsession files directly. You must manually export the data from the Visual Studio Profiler into text files.

    Steps to export:

    1. Open the desired view in Visual Studio (e.g., Allocations or Functions).
    2. Select the rows: Click the first row, hold Shift, and click the last row to select the entire table.
    3. Right-click and select Copy.
    4. Paste the data into a new text file and save it.
    5. 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.

  6. Install Microsoft.OData.Client via NuGet

    main

    You can install the Microsoft.OData.Client package to consume OData services (supporting OData v4 and v4.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.Client
  7. Run load tests and collect traces

    main

    Load Tests

    Load tests measure request round-trips to evaluate how libraries handle concurrent requests. Use loadtests.yml to run these scenarios. You can specify the writer implementation using the writer variable.

    Example (Serialization Comparisons):

    crank --config loadtests.yml --config lab-windows --scenario SerializationComparisons --application.options.counterProviders System.Runtime --variable writer=ODataMessageWriter

    Collecting Traces

    To collect native trace files (e.g., .etl files via PerfView on Windows) for analysis, use the --[job].collect true option, where [job] is the name of the job in your .yml config.

    Example (Collecting traces for the 'application' job):

    crank --config loadtests.yml --config lab-windows --scenario SerializationComparisons --variable writer=ODataMessageWriter --application.collect true
    crank --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 true
  8. Generate strongly-typed client code with OData Connected Service

    main

    To interact with an OData service using strongly-typed models, use the OData Connected Service extension in Visual Studio. This automates the creation of the client code required to map service entities to .NET classes.

    1. Install the extension: Search for OData Connected Service in Extensions > Manage Extensions in Visual Studio, or download it from the Visual Studio Marketplace.
    2. 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.
  9. Build and test OData .NET using Visual Studio

    main

    To build and test the project in Visual Studio, open the OData.sln shortcut 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.

  10. Use Results Comparer to find performance regressions

    main

    The 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%