This tutorial shows how to create a .NET Core Application using Entity Framework Core for an Oracle database. It uses dotConnect for Oracle, a high-performance ADO.NET provider from Devart. The tutorial demonstrates Database-First approach to create an Entity Framework Core model and generate the corresponding code.
Entity Framework Core implements Database-First approach via the Scaffold-DbContext command of Package Manager Console. This command allows quick generation of a DbContext and entity type classes for a specified database, but it doesn't provide much options for customization.
In this tutorial, we will show Database-First approach using our dedicated ORM designer and code generation tool - Entity Developer. It supports Database-First, Model-First, or mixed developer approaches and allows you to quickly generate a model from a database, tweak it visually, automatically apply model changes to a database, if necessary, and generate code. Entity Developer seamlessly integrates into Visual Studio, allows testing the model with LINQ Queries at design-time, supports integration with Visual Studio refactoring and provides its own Model Refactoring feature.
Note: You can find a similar tutorial, using the Scaffold-DbContext command to generate code here.
This tutorial shows how to create a simple console application, powered by Entity Framework Core and using Database-First approach. It uses the tables, we have created in the Creating Database Objects and Inserting Data Into Tables tutorials.
This article consists of the following sections:
Even though we will use dotConnect for Oracle assemblies from NuGet packages, if we want to use Entity Developer for designing the model, we need to also install dotConnect for Oracle from its installer.
This article uses classes from dotConnect for Oracle, a high-performance ADO.NET provider with the ORM support (Entity Framework, NHibernate, and LinqConnect).
Besides dotConnect for Oracle, you will need Visual Studio 2017 or higher with all the necessary updates, installed with the .NET Core cross-platform development tool set selected.
On the left side of the dialog box select Console App.
On the left side of the dialog box select Visual C# -> ASP.NET Core -> Data.
On the left side of the dialog box select Devart EF Core Model.
In our example, we create a model from a database. Select Database First and click Next.
Specify the necessary connection settings. If you want to use a direct connection (without Oracle Client), you need to select the Direct check box and specify SID and port instead of Oracle Home. Click Next.
Select the necessary tables to add to the model and click Next.
On the next page you can configure naming rules for generated classes and properties. Click Next.
Finally, on the next page, you can select templates that will be used for code generation and configure their settings. By default, one EF Core template is selected, which is used to generate classes for the EF Core model. You can add more templates, for example, for adding Data Annotation Metadata classes, Data Transfer Object classes, etc. Click Next, and then click Finish.
The model is ready. You can edit it in Entity Developer and then sync model changes to database tables, or we can modify the database and then sync changes to the model.
For .NET Core/.NET standard projects, dotConnect for Oracle requires the license key specified. If you purchased dotConnect for Oracle, you have received the license key, which should be specified as the license key connection string parameter. For the trial version, you use the trial license key files, generated when installing dotConnect for Oracle.
Trial license key files are generated in the ProgramData\Devart\dotConnect\License\ folder, and this is where dotConnect for Oracle NuGet assemblies look for them by default. If you need to place them to another folder or use them on non-Windows computers, you need to specify the path to them in the license key connection string parameter in the following way:
For our simple example we will just use the model as is, and just add code to get data from one of the entities. So let’s add the following code to the Main function:
[C#]using (var db = new demobaseModel()) { // Creating a new department and saving it to the database var newDept = new DEPT(); newDept.DEPTNO = 60; newDept.DNAME = "DEVELOPMENT"; newDept.LOC = "HOUSTON"; db.DEPTs.Add(newDept); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); // Retrieving and displaying data Console.WriteLine(); Console.WriteLine("All departments in the database:"); foreach (var dept in db.DEPTs) { Console.WriteLine("{0} | {1}", dept.DNAME, dept.LOC); } Console.ReadLine(); }
This code adds a new record to the table, selects data from it, and displays it in the console.
This article shows how to create a .NET Core application, working with an Oracle Database via Entity Framework Core, using dotConnect for Oracle as an Entity Framework Core provider. dotConnect for Oracle is an ADO.NET provider from Devart with support for such ORM solutions as Entity Framework v1 - v6, Entity Framework Core, NHibernate, and Devart's own ORM LinqConnect.
This tutorial uses Entity Developer to generate context and entity classes. Entity Developer is a powerful visual ORM model designer with support for Database First, Model First, and mixed development approaches and powerful code generation.
We use cookies to provide you with a better experience on the Devart website. You can read more about our use of cookies in our Cookies Policy.
Click OK to continue browsing the Devart site. Be aware you can disable cookies at any time.