This guide provides a detailed, step-by-step walkthrough for creating an ASP.NET Core Blazor Web App that performs full CRUD (Create, Read, Update, Delete) operations on an Oracle database. We will build the application progressively, with each section representing a complete, functional stage of development.
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, connecting via proxy servers, embedded servers, and HTTP tunneling.
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:
In this foundational step, our goal is to establish a connection to the Oracle database and display data in a read-only table. This ensures our database connection and data service are correctly configured and provides the foundation for the other CRUD operations.
The data model (Employee.cs)
In your project, create a new folder named Data. Inside it, create a class file named Employee.cs. This class maps directly to the columns of the EMPLOYEES table.
In the Data folder, create a new class EmployeeService.cs. This service encapsulates all database interaction logic. The connection string is read through IConfiguration, which is provided via dependency injection.
You have now built a functional, read-only Blazor application that connects to an Oracle database and displays data in a table. This confirms that your core setup, including the Direct mode connection, dependency injection, and data retrieval, is working correctly.
Insert Oracle data
We will now enhance the application by adding the ability to create new records. This involves adding an EditForm to the UI and implementing the corresponding logic to execute an INSERT SQL command. The new EMPLOYEE_ID is generated using a MAX()+1 subquery, which avoids the need to create a separate Oracle sequence object.
Update the data service (EmployeeService.cs)
Add the InsertEmployeeAsync method to your EmployeeService.cs file.
@code {
private List<Employee>? employees;
private Employee newEmployee = new();
protectedoverrideasync Task OnInitializedAsync()
{
await LoadEmployees();
}
privateasync Task LoadEmployees()
{
employees = await EmployeeSvc.GetAllEmployeesAsync();
}
privateasync Task HandleInsert()
{
await EmployeeSvc.InsertEmployeeAsync(newEmployee);
newEmployee = new(); // Clear the form after insertawait LoadEmployees(); // Refresh the list
}
}
The application can now add new records to the database. Users can enter data in the form, press the Insert Employee button, and the table updates immediately with the new entry. The HIRE_DATE is set automatically to the current date via Oracle's SYSDATE function.
Update Oracle data
In this step, we will implement the ability to edit existing records. This requires adding an Edit button to each table row and a second EditForm that appears when a record is selected for editing.
Update the data service (EmployeeService.cs)
Add the UpdateEmployeeAsync method to EmployeeService.cs.
Add a conditional EditForm for editing. This form only appears when an employee is selected. Place it between the insert form and the table. Also, add an Edit button to each table row and an empty <th> for the actions column.
@code {
private List<Employee>? employees;
private Employee newEmployee = new();
private Employee employeeToEdit = new();
// ... (existing OnInitializedAsync, LoadEmployees, HandleInsert methods) ...privatevoidSetEmployeeForUpdate(Employee employee)
{
// Create a copy to avoid modifying the list directly
employeeToEdit = new Employee
{
EmployeeId = employee.EmployeeId,
FirstName = employee.FirstName,
LastName = employee.LastName,
Email = employee.Email,
Salary = employee.Salary
};
}
privateasync Task HandleUpdate()
{
await EmployeeSvc.UpdateEmployeeAsync(employeeToEdit);
ClearForm();
await LoadEmployees(); // Refresh the list
}
privatevoidClearForm()
{
employeeToEdit = new(); // Reset to hide the edit form
}
}
The application now supports editing data. Users can click Edit on any employee, modify the employee's details in the form, and save the changes to the database. Selecting Cancel hides the edit form without saving.
Delete Oracle data
In the final step, we will implement the delete functionality. This involves adding a Delete button to each table row and using Blazor's JavaScript Interop to display a browser confirmation dialog before deleting the row.
Update the data service (EmployeeService.cs)
Add the DeleteEmployeeAsync method to EmployeeService.cs.
@inject IJSRuntime JSRuntime
<!-- ... (In the foreach loop, next to the Edit button) ... -->
<td>
<button class="btn btn-sm btn-warning" @onclick="() => SetEmployeeForUpdate(emp)">Edit</button>
<button class="btn btn-sm btn-danger" @onclick="() => HandleDelete(emp)">Delete</button>
</td>
Update the UI logic (Employees.razor)
Add the HandleDelete method to the @code block. This method invokes the browser's native confirm() dialog via JavaScript Interop. The record is only deleted if the user clicks OK.
// ... (add this method inside the @code block)privateasync Task HandleDelete(Employee employee)
{
bool confirmed = await JSRuntime.InvokeAsync<bool>("confirm",
$"Are you sure you want to delete {employee.FirstName}{employee.LastName}?");
if (confirmed)
{
await EmployeeSvc.DeleteEmployeeAsync(employee.EmployeeId);
await LoadEmployees(); // Refresh the list
}
}
You have now completed the Blazor application. It provides full CRUD functionality, allowing users to read, create, update, and delete records in the Oracle database through a modern web interface.
Video tutorial: How to Connect .NET Blazor Application to Oracle Database
Conclusion
In this tutorial, we explored how to establish a connection between a Blazor application and an Oracle database using dotConnect for Oracle. Together, we walked through, inserting data, retrieving records, and performing update and delete operations. Thus, the approach covered in this tutorial provides a solid foundation for building agile, data-driven applications that leverage data and integrate with 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.