Oracle .NET Database Samples

repository·master·Indexed 19 days ago

https://github.com/oracle/dotnet-db-samples

Code samples for Oracle Data Provider for .NET (ODP.NET) and other Oracle .NET components. Includes implementations for ODP.NET Core, Managed, and Unmanaged drivers, as well as Oracle Entity Framework Core. Examples cover connectivity to Oracle Autonomous Database, Microsoft Entra ID (Azure AD) token authentication, SSO with service principals, and configuration management using OracleConfiguration, OracleDataSourceCollection, and OracleOnsServerCollection.

Tokens
14.2K
Snippets
34
Records
94
Agent score
65%

What's inside oracle-dotnet-db-samples

  1. Explore Oracle .NET Session Demos from Oracle CloudWorld 2022

    master
    This directory provides access to code samples and tutorials presented during Oracle CloudWorld 2022. The demos cover several key areas of .NET development with Oracle Database, including Entity Framework Core (EF Core) versions 6 and 7, asynchronous vs. synchronous ODP.NET patterns, User-Defined Types (UDT), and advanced features like Binary JSON and Client Initiated Continuous Query Notification (CICQN).
  2. Understand Oracle .NET components

    master

    Oracle provides several free components for .NET developers working with Oracle Database:

    • Oracle Data Provider for .NET (ODP.NET): An optimized ADO.NET data access provider. It supports advanced features like AI vector search, JSON-relational duality views, Real Application Clusters (RAC), and self-updating client caches. It is available in three types:
      • Core: For .NET (Core) runtimes.
      • Managed: For .NET Framework (100% managed code, easy deployment).
      • Unmanaged: For .NET Framework.
    • Oracle Developer Tools for Visual Studio: A Visual Studio Add-in for application lifecycle management, including PL/SQL debugging and schema comparison.
    • Oracle Providers for ASP.NET: A collection of providers for storing ASP.NET website state in an Oracle database.
  3. Access Oracle Database World 2021 .NET Demos

    master
    This directory provides demo code and resources related to the session 'What’s New for .NET and Visual Studio Code Developers in Oracle Database 21c' from Oracle Database World 2021. It includes implementations for ODP.NET with .NET 6, Entity Framework Core 6, User-Defined Types (UDT), and advanced features like Binary JSON and Client Initiated Continuous Query Notification (CICQN).
  4. Use Unmanaged ODP.NET in Managed/Core Projects

    master

    While the samples are designed for Managed ODP.NET or ODP.NET Core, you can use unmanaged ODP.NET by making the following changes:

    1. Incorporate Oracle.DataAccess.dll into your project.
    2. Add the unmanaged ODP.NET namespace references:
      • using Oracle.DataAccess.Client;
      • using Oracle.DataAccess.Types;
  5. Execute Oracle PL/SQL stored procedures with EF Core

    master

    You can execute Oracle PL/SQL stored procedures and retrieve result sets in Entity Framework Core using anonymous PL/SQL blocks combined with the FromSql extension method.

    This sample demonstrates two patterns for handling result sets via REF CURSOR:

    1. Explicitly bound REF Cursor: Requires the REF CURSOR parameter to be explicitly bound to the stored procedure statement.
    2. Implicitly bound REF Cursor: Does not require explicit binding of the REF CURSOR parameter.

    Relevant SQL setup files:

    • return-implicit-ref-cursor-stored-procedure.sql: Creates a procedure returning an implicitly bound REF CURSOR.
    • return-ref-cursor-stored-procedure.sql: Creates a procedure returning an explicitly bound REF CURSOR.
  6. Configure ODP.NET EF Core for Oracle Autonomous Database (ADB)

    master

    To connect to an Oracle Autonomous Database (ADB) using ODP.NET Entity Framework Core, you must configure the OracleConfiguration properties and provide a valid connection string. ADB typically requires TCP with SSL (TCPS) connections, which necessitates using an Oracle wallet to store security credentials.

    Follow these steps for setup:

    1. Set TNS Admin Path: Assign the directory containing your tnsnames.ora and sqlnet.ora files to OracleConfiguration.TnsAdmin.
    2. Set Wallet Location: Assign the directory containing your ADB wallet files to OracleConfiguration.WalletLocation.
    3. Configure Connection String: Provide a connection string that includes the user id, password, and data source. The data source should typically be the ADB TNS name.

    In this implementation pattern, these configurations are applied within the OnConfiguring method of your DbContext.

    // Conceptual implementation within a DbContext
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        OracleConfiguration.TnsAdmin = "/path/to/tnsnames_and_sqlnet_directory";
        OracleConfiguration.WalletLocation = "/path/to/adb_wallet_directory";
    
        optionsBuilder.UseOracle("user id=my_user;password=my_password;data source=my_adb_tns_name");
    }
  7. Set up Oracle Entity Framework Core 2.x with Dependency Injection

    master

    This sample demonstrates how to integrate ASP.NET Core and Dependency Injection with Oracle Entity Framework Core 2.x.

    Note: This sample is specifically for EF Core 2.x and does not support later versions.

    To run the application, follow these steps:

    1. Install the NuGet Package: Add the Oracle.EntityFrameworkCore assembly from the NuGet Gallery to your project.
    2. Configure Connection Settings: Open appsettings.json and provide your Oracle database credentials, specifically the User Id, Password, and Data Source information.
    3. Initialize the Database: Use EF Core migrations to create the required schema (specifically the Blogs table) and populate it with initial data.

    Once these steps are completed, running the application will allow the web page to successfully return results from the Oracle database.