You can install the driver by using the Windows installer.
After you receive the license key, add it to your connection strings to connect to the data source.
This tutorial shows how to use Entity Framework Core to perform operations in .NET applications. With dotConnect for Oracle, we'll create EF Core models using Scaffold-DbContext and Entity Developer, build a console application, and implement CRUD operations using a robust connection class.
Fully supports EF Core, Dapper, NHibernate, LinqConnect, and other technologies for efficient data management.
Conforms to the latest ADO.NET standards and innovations for seamless integration with .NET applications.
Offers many Oracle-specific features and fully supports all unique data types for accurate and complete data representation.
Provides robust security with support for SSL/SSH connections, proxy authentication, and OS authentication (NTLM).
Features native integration with Visual Studio and complete design-time support for accelerated development.
Includes priority support, detailed documentation, and regular updates for continuous improvement.
You can start using dotConnect for Oracle immediately with a 30-day free trial. Choose one of the following installation options:
Using the built-in Data Explorer, configure the connection to Oracle and then select the objects you want to use in your project.
1. In Visual Studio, click Tools on the menu bar and select Connect to Database from the drop-down list.
2. In the Add Connection window, choose the Oracle data source, fill in the connection details for your Oracle database, and click OK to proceed.
In Server Explorer, select the tables and fields you want to use. In our tutorial, we will use the EMPLOYEES table.
Once you have configured the database, you can move on to the next step—creating an EF Core model. You can do this in two ways: using Scaffold-DbContext or via Entity Developer.
Entity Developer allows you to visually design and generate EF Core models, making database application development faster, easier, and more efficient. If you don't have it already installed, close your Visual Studio instance and download Entity Developer. Install it on your machine following the on-screen instructions.
Follow the detailed illustrated guide to create your database model using Entity Developer. When this process is complete, the model you created opens, so you can work with it.
It also creates the DbContext class:
You can use Scaffold-DbContext to generate DbContext and entity classes for your Oracle database. Run the following command, replacing values with your actual credentials:
Scaffold-DbContext "DataSource=127.0.0.1;Port=1521;SID=XE;UserId=TestUser;Password=TestPassword;LicenseKey=**********;" -provider Devart.Data.Oracle.Entity.EFCore -OutputDir Models
After you execute this command, the ModelContext file and the Models folder containing the table entity classes are generated.
| Property | Meaning |
|---|---|
| Direct | Property indicating whether direct mode is to be used |
| Host | IP address or hostname of the Oracle server |
| Port | Port number for the Oracle server |
| ServiceName | Service name for the database instance |
| SID | Oracle System Identifier (SID) for the database instance |
| UserId | Oracle database username |
| Password | Password associated with the Oracle database username |
| LicenseKey | License key (only required when using .NET Standard compatible assemblies) |
This section shows how to connect to an Oracle database and retrieve the first 10 rows from the EMPLOYEES table using EF Core. We'll query the data and display it in the console for verification.
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new DataModel())
{
var employees = context.EMPLOYEEs
.Take(10)
.ToList();
Console.WriteLine("First 10 Employees:");
Console.WriteLine("------------------");
foreach (var employee in employees)
{
Console.WriteLine($"ID: {employee.EMPLOYEEID}, Name: {employee.FIRSTNAME} {employee.LASTNAME}, Email: {employee.EMAIL}, Hire Date: {employee.HIREDATE:yyyy-MM-dd}, Salary: {employee.SALARY:C}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
Run the application. If everything is set up correctly, the console will display the first 10 records from the EMPLOYEES table.
Here, we insert a new employee record into the EMPLOYEES table. EF Core's Add method is used to stage the record, and SaveChanges persists it to the database. The console displays the inserted record for debugging.
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new DataModel())
{
var newEmployee = new EMPLOYEE
{
FIRSTNAME = "John",
LASTNAME = "Doe",
EMAIL = "[email protected]",
HIREDATE = DateTime.Now,
SALARY = 75000.00
};
context.EMPLOYEEs.Add(newEmployee);
context.SaveChanges();
Console.WriteLine($"New employee added with ID: {newEmployee.EMPLOYEEID}");
Console.WriteLine();
var employees = context.EMPLOYEEs
.Take(10)
.ToList();
Console.WriteLine("First 10 Employees:");
Console.WriteLine("------------------");
foreach (var employee in employees)
{
Console.WriteLine($"ID: {employee.EMPLOYEEID}, Name: {employee.FIRSTNAME} {employee.LASTNAME}, Email: {employee.EMAIL}, Hire Date: {employee.HIREDATE:yyyy-MM-dd}, Salary: {employee.SALARY:C}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
Sample output:
This section shows how to update the record with EMPLOYEEID 41 by changing the employee’s first and last name. We retrieve the record, modify the properties, and call SaveChanges to persist the changes.
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new DataModel())
{
var employeeToUpdate = context.EMPLOYEEs.FirstOrDefault(e => e.EMPLOYEEID == 41);
if (employeeToUpdate != null)
{
Console.WriteLine($"Before update - ID: {employeeToUpdate.EMPLOYEEID}, Name: {employeeToUpdate.FIRSTNAME} {employeeToUpdate.LASTNAME}");
employeeToUpdate.FIRSTNAME = "UpdatedFirst";
employeeToUpdate.LASTNAME = "UpdatedLast";
context.SaveChanges();
Console.WriteLine($"After update - ID: {employeeToUpdate.EMPLOYEEID}, Name: {employeeToUpdate.FIRSTNAME} {employeeToUpdate.LASTNAME}");
}
else
{
Console.WriteLine("Employee with ID 41 not found.");
}
Console.WriteLine();
var employees = context.EMPLOYEEs
.ToList();
Console.WriteLine("All Employees:");
Console.WriteLine("--------------");
foreach (var employee in employees)
{
Console.WriteLine($"ID: {employee.EMPLOYEEID}, Name: {employee.FIRSTNAME} {employee.LASTNAME}, Email: {employee.EMAIL}, Hire Date: {employee.HIREDATE:yyyy-MM-dd}, Salary: {employee.SALARY:C}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
The console shows the updated record for verification:
Finally, we delete the employee with EMPLOYEEID 41 from the EMPLOYEES table. The record is removed using the Remove method, and SaveChanges commits the deletion.
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new DataModel())
{
var employeeToDelete = context.EMPLOYEEs.FirstOrDefault(e => e.EMPLOYEEID == 41);
if (employeeToDelete != null)
{
context.EMPLOYEEs.Remove(employeeToDelete);
context.SaveChanges();
}
var employees = context.EMPLOYEEs.ToList();
foreach (var employee in employees)
{
Console.WriteLine($"ID: {employee.EMPLOYEEID}, Name: {employee.FIRSTNAME} {employee.LASTNAME}, Email: {employee.EMAIL}, Hire Date: {employee.HIREDATE:yyyy-MM-dd}, Salary: {employee.SALARY:C}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
The console confirms the deletion:
In this tutorial, we've demonstrated how the integration of Entity Framework Core with Oracle using dotConnect for Oracle streamlines data operations in .NET applications. The rich features of dotConnect for Oracle, combined with the simplicity of Entity Framework Core, provide a powerful and efficient way to handle database interactions in Oracle-powered applications. With these tools and techniques, you can confidently build scalable and maintainable .NET solutions that leverage Oracle databases.
License Key parameter for a working connection.
License Key value, then create an OracleConnection instance with this string and call Open() for it inside a try-catch block to test and handle connection errors.
Scaffold-DbContext with a dotConnect connection string (including License Key) to generate the DbContext and entity classes.
I'm a technical content writer who loves turning complex topics — think SQL, connectors, and backend chaos–into content that actually makes sense (and maybe even makes you smile). I write for devs, data folks, and curious minds who want less fluff and more clarity. When I'm not wrangling words, you'll find me dancing salsa, or hopping between cities.