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.
Why dotConnect for Oracle?
Advanced ORM support
Fully supports EF Core, Dapper, NHibernate, LinqConnect, and other technologies for efficient data management.
Full ADO.NET compliance
Conforms to the latest ADO.NET standards and innovations for seamless integration with .NET applications.
Oracle-specific data types
Offers many Oracle-specific features and fully supports all unique data types for accurate and complete data representation.
Secure connection options
Provides robust security with support for SSL/SSH connections, proxy authentication, and OS authentication (NTLM).
IDE integration
Features native integration with Visual Studio and complete design-time support for accelerated development.
Priority support & frequent updates
Includes priority support, detailed documentation, and regular updates for continuous improvement.
Download and activate dotConnect for Oracle
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.
Create an EF Core model from the database
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.
Create an EF Core model 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:
Create an EF Core model using Scaffold-DbContext
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:
After you execute this command, the ModelContext file and the Models folder containing the table entity classes are generated.
Direct mode options properties
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)
Connect to Oracle and retrieve data
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.
Run the application. If everything is set up correctly, the console will display the first 10 records from the EMPLOYEES table.
Insert new records using EF Core
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.
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.
classProgram
{
staticvoidMain(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:
Delete Oracle data using EF Core
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.
classProgram
{
staticvoidMain(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:
Video tutorial: Connect to Oracle with EF Core
Conclusion
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.
FAQ
How do you install and activate dotConnect for Oracle in a .NET project?
Install dotConnect for Oracle via the EXE installer or by adding the Devart.Data.Oracle NuGet package to your project, then obtain your personal activation key from your Devart Customer Portal and include it in the connection string via the License Key parameter for a working connection.
How do you create a connection to Oracle using dotConnect in C#?
Define a connection string that includes host, user ID, password, database, and the 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.
How do you enable encryption for secure Oracle connections with dotConnect?
Use Oracle Native Network Encryption by configuring encryption in the sqlnet.ora file on both client and server sides. No special parameters are required in the connection string.
Can you connect to Oracle using Entity Framework Core and dotConnect?
Yes, you can either use Entity Developer to visually create an EF Core model from the database or run Scaffold-DbContext with a dotConnect connection string (including License Key) to generate the DbContext and entity classes.
Is it possible to connect to Oracle using Visual Studio Server Explorer with dotConnect?
Yes, it is possible. All you need to do is navigate to Visual Studio Server Explorer, add a new Data Connection, choose dotConnect for Oracle as the data provider, enter your credentials, test the connection, and then browse Oracle data directly in Visual Studio.
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.