![]() Step 2: Open the Command Prompt and navigate to the Core_APIOracle project folder. Listing 5: Register the OraDbContext class in the Depednency Container Add the code as shown in Listing 5 to register the OraDbContext class in dependency container (options => Let's modify the Program.cs to register the OraDbContext class in the dependency container so that the connection with Oracle database will be established and using Code-First migration commands tables will be created in the Oracle database. (NoteL: Read the Oracle Database Users and Roles for more information.) In the connection string I have used Privilege=SYSDBA so that the required access on database for Read/Write operations are granted for the sys user. In the connection string, we have set the Data Source as the Oracle instance running on the port 1521 on the local machine inside the Docker Container. "OraDbConnection": "User Id=sys Privilege=SYSDBA Data Source=localhost:1521/ORASID " Modify the appsettings.json file by adding Connection String as shown in listing 4 We need to configure the Connection String for the Oracle database using appsettings.json file. Using this class, we will be able to connect to the Oracle database and perform Read/Write Operations. Protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) Public OraDbContext(DbContextOptions options):base(options) In this class, file add code as shown in Listing 3 In the Models folder, add a new class file and name it as OraDbContext.cs. We need to create DbContext class for the Code-First approach. In this class file, we will add an entity class as shown in Listing 2 using ![]() In this folder add a new class file and name it as ProductsInfo.cs. Step 2: In the project, add a new folder and name it Models. In this project add the following NuGet packages Step 1: Open Visual Studio 2022 and create a new ASP.NET Core API application targeted to. Once the database is started we can access it from Oracle SQL Developer as shown in figure 1. The command shown in Listing 1 will take 2-3 minutes to start the database. The ORACLE_PDB is the Oracle database service name. To uniquely identify the database instance the SID is set as ORASID. ![]() We are running an image on oracontainer and the database is accessible on port 1521. To run the Docker Image run the command as shown in Listing 1 from the Command Promptĭocker run -name oracontainer -p 1521:1521 -p 5500:5500 -e ORACLE_SID=ORASID -e ORACLE_PDB=ORCLPDB1 -e -e ORACLE_CHARACTERSET=A元2UTF8 To interact with the database from the image, I have used Oracle SQL Developer. This image can be downloaded from this link. To implement code for the application, I have an Oracle 19c Docker image. This data provider allows using Code-First and Database-First approaches to perform Read/Write Operations with Oracle database. NET Core apps using Entity Framework Core. ODP.NET is used to access data from the Oracle database in the. NET Core apps the use Entity Framework Core is common. NET Core is the most popular technology for building modern apps, the scenarios for accessing the Oracle database in. Since Oracle is one of the most powerful databases, various enterprise applications are using it for the past several years and since the. The reason behind writing a post on this is, recently while conducting training, one of my students raised the query regarding the EF Core with Oracle. In this article, we will see how to use Oracle Database with Entity Framework Core with Code-First Approach.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |