'Table Does Not Exist while using .NET 6 and Oracle.EntityFrameworkCore 6.21.5
I am trying out Razor and Core for the first time and just want to connect to our oracle DB and bring back data.
An unhandled exception occurred while processing the request. OracleException: ORA-00942: table or view does not exist OracleInternal.ServiceObjects.OracleConnectionImpl.VerifyExecution(out int cursorId, bool bThrowArrayBindRelatedErrors, SqlStatementType sqlStatementType, int arrayBindCount, ref OracleException exceptionForArrayBindDML, out bool hasMoreRowsInDB, bool bFirstIterationDone)*
ModelContext.cs snippet
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("TRADMIN")
.UseCollation("USING_NLS_COMP");
modelBuilder.Entity<Agency>(entity =>
{
entity.ToTable("AGENCY");
entity.HasIndex(e => e.Description, "IX_DESCRIPTION")
.IsUnique();
entity.Property(e => e.Id)
.HasColumnType("NUMBER")
.ValueGeneratedOnAdd()
.HasColumnName("ID");
entity.Property(e => e.Description)
.HasMaxLength(250)
.IsUnicode(false)
.HasColumnName("DESCRIPTION");
entity.Property(e => e.InactiveDate)
.HasColumnType("DATE")
.HasColumnName("INACTIVE_DATE");
});
Tried setting the default schema just in case it was a schema problem the following way in the Data folder DbContext file and it did not make a difference
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//set a default schema for all tables
modelBuilder.HasDefaultSchema("tradmin");
}
Debug Console
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (83ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
SELECT "a"."Id", "a"."Description", "a"."InactiveDate"
FROM "Agency" "a"
fail: Microsoft.EntityFrameworkCore.Infrastructure[0]
2022-03-29 14:35:38.690640 ThreadID:12 (ERROR) OracleExecutionStrategy.Execute() : Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-00942: table or view does not exist
appsettings.json snippet
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DevConnection": "User Id=*****;Password=*****; Data Source=****;"
}
Program.cs snippet
using Microsoft.EntityFrameworkCore;
using SDD_Training.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddDbContext<ApplicationDBContext>(options => options.UseOracle(
builder.Configuration.GetConnectionString("DevConnection")
)); ;
var app = builder.Build();
ApplicationDBContext.cs snippet
using Microsoft.EntityFrameworkCore;
using SDD_Training.Models;
namespace SDD_Training.Data
{
public class ApplicationDBContext : DbContext
{
public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)
{
}
public DbSet<Agency> Agency { get; set; }
}
}
models\Agency.cs snippet
using System;
using System.Collections.Generic;
namespace SDD_Training.Models
{
public partial class Agency
{
public decimal Id { get; set; }
public string? Description { get; set; }
public DateTime? InactiveDate { get; set; }
}
}
agency\index.cshtml.cs snippet
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using SDD_Training.Data;
using SDD_Training.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SDD_Training.Pages.agencies;
public class IndexModel : PageModel
{
private readonly ApplicationDBContext _db;
public IEnumerable<Agency> Agency { get; set; }
public IndexModel(ApplicationDBContext db)
{
_db = db;
}
public void OnGet()
{
Agency = _db.Agency;
}
}
agency/index.cshtml snippet
<table>
<thead>
<tr>
<th>
ID
</th>
<th>
Agency Name
</th>
<th>
Inactive Date
</th>
</tr>
</thead>
<tbody>
@foreach(var obj in Model.Agency)
{
<tr>
<td width="10%">
@obj.Id
</td>
<td width="50%">
@obj.Description
</td>
<td width="40%">
@obj.InactiveDate
</td>
</tr>
}
</tbody>
</table>
Agency Table I am trying to display
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

